我尝试了我在网上找到的一切。将显示后端,包括动态段(使用select等)。但最简单的“渲染回调”不会出现在前端。
插件。php
/**
* Plugin Name: My Dynamic Block
*/
function my_plugin_render_dynamic_block( ) {
return \'<h1>Sample Block</h1>\';
}
function register_dynamic_block() {
wp_register_script(
\'dynamic-block\',
plugins_url( \'/dist/block.js \', __FILE__),
array( \'wp-blocks\', \'wp-element\', \'wp-editor\' ),
filemtime( plugin_dir_path( __FILE__ ) . \'dist/block.js\' )
);
register_block_type(
\'my-plugin/dynamic-block\',
[
\'editor_script\' => \'dynamic-block\',
\'render_callback\' => \'my_plugin_render_dynamic_block\',
]
);
}
add_action(\'init\', \'register_dynamic_block\');
阻止。js公司
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
registerBlockType( \'my-plugin/dynamic-block\', {
title: \'My Dynamic Block\',
icon: \'megaphone\',
category: \'widgets\',
edit({attributes}) {
return (
<div>Content</div>
);
},
save() {
return null;
},
} );