这篇文章是让Woodmart主题中的html block兼容Stackable插件,Woodmart主题中的html block默认是不支持古腾堡的,更别提古腾堡插件Stackable。
将下面的代码放到主题functions.php里
让html block支持古腾堡:
// 让html block支持古腾堡
add_filter('register_post_type_args', function($args, $post_type) {
$supported_post_types = array("cms_block");
if (in_array($post_type, $supported_post_types)) {
$args['show_in_rest'] = true;
}
return $args;
}, 10, 2);
让html block兼容Stackable插件:
// html block加载stackable样式
add_filter("wpml_object_id",function($id,$cms_block){
$post = get_post( $id );
if ( ! $post || $post->post_type != 'cms_block' || ! $id || $cms_block != 'cms_block') {
return;
}
// 兼容Stackable
Stackable_Init::register_frontend_assets();
wp_enqueue_style( 'ugb-style-css' );
wp_enqueue_style( 'ugb-style-css-nodep' );
wp_enqueue_script( 'ugb-block-frontend-js' );
do_action( 'stackable_block_enqueue_frontend_assets' );
return $id;
},8,2);
© 版权声明
THE END
暂无评论内容