Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a setting in index.php

if(get_option('cb2_blog_home')){
    cb_get_blog_links();
}

This code allows the home page blog index to be turned on and off. The cb_get_blog_links() function draws out the list of blog post summaries.

And, in the customizer, I have a checkbox to allow this value cb2_blog_home to be set. However, it has no effect. Its as if the option is always true.

Any ideas why?

Inside that function, there are several variables that I'm also setting with the customizer. Those all work perfectly.

Here's the full customizer code. Everything fires perfectly except the home blog setting. The only thing I can come up with is that one is a function and the others are variables within the function.

function cb_customize_register($wp_customize){

        $wp_customize->add_section('cb_customizer_blog', array(
                'title'    => __('Theme Blog Settings', 'Theme'),
                'priority' => 120,
        ));

                //Show & Hide Blog Links on Home
                $wp_customize->add_setting('cb2_blog_home', array(
                        'default'        => '',
                        'capability'     => 'edit_theme_options',
                        'type'           => 'option',
                ));

                $wp_customize->add_control('cb2_blog_home', array(
                        'label'      => __('Enable Home Blog', 'Theme'),
                        'section'    => 'cb_customizer_blog',
                        'settings'   => 'cb2_blog_home',
                        'type'   => 'checkbox',
                        'priority' => 125,
                ));

                //Home Blog Post Count
                $wp_customize->add_setting('cb2_blog_home_count', array(
                        'default'        => '3',
                        'capability'     => 'edit_theme_options',
                        'type'           => 'option',
                ));

                $wp_customize->add_control('cb2_blog_home_count', array(
                        'label'      => __('Home Blog Post Count', 'Theme'),
                        'section'    => 'cb_customizer_blog',
                        'settings'   => 'cb2_blog_home_count',
                        'priority' => 130,
                ));


                //Show & Hide Home Blog Title Heading
                $wp_customize->add_setting('cb2_blog_home_title_hide', array(
                        'default'        => '',
                        'capability'     => 'edit_theme_options',
                        'type'           => 'option',
                ));

                $wp_customize->add_control('cb2_blog_home_title_hide', array(
                        'label'      => __('Hide Home Blog Title', 'Theme'),
                        'section'    => 'cb_customizer_blog',
                        'settings'   => 'cb2_blog_home_title_hide',
                        'type'   => 'checkbox',
                        'priority' => 135,
                ));

                //Show & Hide Home Blog Author Byline
                $wp_customize->add_setting('cb2_blog_index_author', array(
                        'default'        => '',
                        'capability'     => 'edit_theme_options',
                        'type'           => 'option',
                ));

                $wp_customize->add_control('cb2_blog_index_author', array(
                        'label'      => __('Hide Blog Author Byline', 'Theme'),
                        'section'    => 'cb_customizer_blog',
                        'settings'   => 'cb2_blog_index_author',
                        'type'   => 'checkbox',
                        'priority' => 140,
                ));

            //Show & Hide Home Blog Date
            $wp_customize->add_setting('cb2_blog_index_date', array(
                        'default'        => '',
                        'capability'     => 'edit_theme_options',
                        'type'           => 'option',
                ));

                $wp_customize->add_control('cb2_blog_index_date', array(
                        'label'      => __('Hide Blog Date', 'Theme'),
                        'section'    => 'cb_customizer_blog',
                        'settings'   => 'cb2_blog_index_date',
                        'type'   => 'checkbox',
                        'priority' => 145,
                ));

}

add_action('customize_register', 'cb_customize_register');
share|improve this question
    
When I tested your code the option key cb2_blog_home was being set as expected: 1, if checked. empty, if unchecked. –  Rachel Baker Feb 1 at 18:27
    
Rachel, can you tell me how you are able to check the key values in the post? –  Scott B Feb 2 at 1:13
    
scott-b, I was checking the database values. If I enter: $temp = get_option('cb2_blog_home'); echo var_dump( $temp ); into a theme's header.php I am showing the expected values of $temp = false|true. –  Rachel Baker Feb 2 at 2:57
    
This one has me been bugging me. The database values are correct but the customizer.php and front end results don't always match. –  s_ha_dum Feb 2 at 15:38
    
Any progress on that question? Debugging code available for later readers to give it a try? –  kaiser Feb 17 at 23:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.