额外的古腾堡编辑

时间:2019-04-04 08:28:29

标签: wordpress wordpress-gutenberg gutenberg-blocks

有人对如何在WordPress中集成/激活第二个gutenberg编辑器有解决方案吗?

目前,古腾堡(Gutenberg)编辑器解析the_content()。

我想要实现的是标题介绍文本,用户可以在其中添加默认内容以外的自己的块。

3 个答案:

答案 0 :(得分:0)

目前还没有这样的事情,但WordPress的目标是将来。古腾堡(Gutenberg)编辑器是WordPress的第一阶段,它包含了现代JavaScript,第二阶段正在开发中。第1阶段仅针对WordPress的内容部分,而第2阶段则针对标题,菜单,小部件等所有内容。第2阶段的最终结果是使用Gutenberg行为编辑每个部分。

阶段2:https://make.wordpress.org/core/2018/12/08/gutenberg-phase-2/

这意味着目前您只能进行自定义插件开发或使用ACF之类的插件。

答案 1 :(得分:-1)

最简单的方法可能是使用诸如“高级自定义字段”之类的插件将“所见即所得”字段添加到正在编辑的内容类型中(可能是Post还是Page?)。

如果要将其应用于多个页面,请创建一个自定义模板以呈现该字段。 ACF的最后一部分内容简短tutorial(假设您知道如何向WP添加自定义模板)。

如果这是少数页面,则可以在页面上使用shortcode来显示内容。

答案 2 :(得分:-1)

要正确使用wp_editor,请像这样使用它:

// add the admin settings and such
add_action('admin_init', 'wp_your_plugin_admin_init');
function wp_your_plugin_admin_init(){
register_setting( 'wp_your_plugin_settings', 'wp_your_plugin_settings', 'wp_your_plugin_settings_validate');
add_settings_field('wp_your_plugin_user_custom_text', __('Enter your message','wp_your_plugin'), 'wp_your_plugin_user_custom_text', 'wp_your_plugin', 'wp_your_plugin_main');

function wp_your_plugin_user_custom_text() {
$options = get_option('wp_your_plugin_settings');
$settings  = array('media_buttons' => true,'textarea_rows' => 5,'textarea_name' => 'user_custom_text');
wp_editor( $options['user_custom_text'],'user_custom_text', $settings  );}  

// validate  
function wp_your_plugin_settings_validate() {
$options = get_option('wp_your_plugin_settings');


if ( empty($_POST['user_custom_text']) ){
    $options['user_custom_text'] =  __('Enter your own content, it will be below the original message','wp_your_plugin');// as set when the plugin activated
}else{
    $options['user_custom_text'] =  wp_kses_post($_POST['user_custom_text']) ;}// u need to Sanitize to be able to get the media to work
相关问题