0
votes

I am trying to add an extra setting in the Wordpress customizer. Can you add extra settings in the site title & tagline section or do you have to create your own section? This is the code I have so far in my functions.php file:

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' );

If I try to go to the customize theme page in the admin area though I get the following error:

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
2

2 Answers

0
votes

Yes, you can add to the title and tagline section. Try using this code:

$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'
            )
        )
    )
);

Read more about the Theme Customization API at the WordPress Codex.

0
votes

I fixed it in the end it's because I had to define a setting first so this is the working code:

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' );