2017-02-21 65 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'; 
相關問題