【问题标题】:wordpress Call to a member function add_section() on a non-object in functions.php line 5wordpress 在functions.php第5行的非对象上调用成员函数add_section()
【发布时间】:2016-05-24 05:06:11
【问题描述】:

嘿,我对 php 和 wordpress 开发有点陌生,我只是在尝试 wordpress 的工作方式和主题的工作方式。现在我已经尝试多次查找这个但没有帮助。这总是一些不同的东西,对那些人有用的东西,对我没用。这是代码,

    <?php

function sandor_hero_cap() {

$wp_customize->add_section('sandor_subhead_title', array(
        'title' => __('Sub-Header', 'sandor'),
));

$wp_customize->add_setting('sandor_subhead_title', array(
        'default' => 'A Virtual PLAYGROUND',
        'capability' => 'edit_theme_options',
        'sanitize_callback' => 'sanitize_text_field'
));

$wp_customize->add_control('sandor_subhead_title', array(
        'label' => __('Sub-Header Title', 'sandor'),
        'section' => 'sandor_subhead_section',
        'priority' => 5,
        'settings' => 'sandor_subhead_title'
));

}

add_action( 'customize_register', 'sandor_hero_cap' );

?>

我得到的错误是:

Call to a member function add_section() on a non-object in functions.php line 5 我已经尝试了很多东西,但似乎没有任何效果,希望你们能帮助我解决这个问题。谢谢:)

【问题讨论】:

    标签: php wordpress web


    【解决方案1】:

    您缺少$wp_customize 参数。而且,如果我没记错的话,为add_settingadd_control 使用不同的名称可能是个好主意。请参阅下面的代码。

    function sandor_hero_cap($wp_customize) {
    
        $wp_customize->add_section('sandor_subhead_title', array(
        'title' => __('Sub-Header', 'sandor'),
    ));
    
        $wp_customize->add_setting('sandor_playground', array(
        'default' => 'A Virtual PLAYGROUND',
        'capability' => 'edit_theme_options',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    
    $wp_customize->add_control('sandor_playground', array(
        'label' => __('Sub-Header Title', 'sandor'),
        'section' => 'sandor_subhead_section',
        'priority' => 5,
        'settings' => 'sandor_subhead_title'
    ));
    
    }
    
    add_action( 'customize_register', 'sandor_hero_cap' );
    

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 2017-04-09
      • 2015-08-29
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 2015-09-15
      • 1970-01-01
      • 2015-01-27
      相关资源
      最近更新 更多