2014-07-09 27 views
0

我試圖在Wordpress定製器中添加一個額外的設置。您是否可以在網站標題&標語部分中添加額外設置,或者您是否必須創建自己的部分?這是代碼我到目前爲止在我functions.php文件:在wordpress中向定製器添加設置時發生致命錯誤

function mytheme_customize_register($wp_customize) 
{ 
    $wp_customize->add_control(
     new WP_Customize_Control(
      $wp_customize, 
      'your_setting_id', 
      array(
       'label'   => __('Your Label Name', 'theme_name'), 
       'section'  => 'title_tagline', 
       'settings'  => 'your_setting_id', 
       'type'   => 'text' 
      ) 
     ) 
    ); 
} 
add_action('customize_register', 'mytheme_customize_register'); 

如果我試圖去定義主題頁面在管理方面,雖然我得到以下錯誤:

Fatal error: Call to a member function check_capabilities() on a non-object in C:\xampp\htdocs\one-gas\wp-includes\class-wp-customize-control.php on line 161 

回答

0

我定它到底是因爲我必須先定義設置,所以這是工作代碼:

function mytheme_customize_register($wp_customize) 
{ 
    $wp_customize->add_setting('subtagline', array(
     'default' => 0, 
     'type' => 'option' 
    )); 

    $wp_customize->add_control(
     new WP_Customize_Control(
      $wp_customize, 
      'subtagline', 
      array(
       'label'   => __('Sub Tagline', 'One Gas'), 
       'section'  => 'title_tagline', 
       'settings'  => 'subtagline', 
       'type'   => 'text' 
      ) 
     ) 
    ); 
} 
add_action('customize_register', 'mytheme_customize_register'); 
0

是的,您可以添加到標題和標語部分。請嘗試使用此代碼:

$wp_customize->add_control(
    new WP_Customize_Control(
     $wp_customize, 
     'your_setting_id', 
     array(
      'label'   => __('Your Label Name', 'theme_name'), 
      'section'  => 'title_tagline', 
      'settings'  => 'your_setting_id', 
      'type'   => 'text' 
      ) 
     ) 
    ) 
); 

瞭解更多關於Theme Customization API在WordPress的法典。

+0

您好,首先感謝試圖幫助。我試過了你的代碼,但是得到一個錯誤(查看更新後的問題) – geoffs3310

+0

你需要改變通用信息,比如setting_id和theme_name。這就是爲什麼它不起作用。 – michaelrmcneill

相關問題