2017-02-21 88 views
3

基本Wordpress主题显示在定制这个编辑按钮:显示部分编辑按钮

enter image description here

我想将它添加到我自己的主题为好。 根据this post,要求打开选择性刷新

我试图用我的自定义部分来做到这一点。在add_theme_support('customize-selective-refresh-widgets');selective_refresh->add_partial()仔细看,因为我以为这是唯一的事情,我不得不补充:

function toorgmot_customize_register($wp_customize){ 

    add_theme_support('customize-selective-refresh-widgets'); 

    $wp_customize->add_section('toorgmot-welcome-message-section',array(
     'title' => 'Welcome Message' 
    )); 

    $wp_customize->add_setting('toorgmot-welcome-message-text',array(
     'default' => 'Hallo en welkom!' 
    )); 

    $wp_customize->add_control(new WP_Customize_Control($wp_customize,            
     'toorgmot-welcome-message-control', array(
     'label' => 'Text', 
     'section'=> 'toorgmot-welcome-message-section', 
     'settings' => 'toorgmot-welcome-message-text' 
    ))); 

    $wp_customize->selective_refresh->add_partial('toorgmot-welcome-message-text', array(
     'selector' => '.welcome-message', 
     'render_callback' => function() { 
      echo get_theme_mod('toorgmot-welcome-message-text'); 
     }, 
    )); 
    } 

    add_action('customize_register','toorgmot_customize_register'); 

它不会返回错误。额外的部分在定制器内部是可编辑的,就像我想要的一样。但是,选择性刷新不起作用,编辑按钮也不显示。

+0

你是你想什么明确的,但什么是你的问题的症状是什么? –

+0

没有错误,但编辑按钮不显示,选择性刷新也不起作用(整个页面在我在主题自定义内进行更改时重新加载)@GregTarsa –

回答

0

您需要添加代码:

$setting = $wp_customize->get_setting('toorgmot-welcome-message-text'); 
$setting->transport = 'postMessage'; 

或者只是:

$wp_customize->get_setting('toorgmot-welcome-message-text')->transport = 'postMessage'; 
相关问题