3

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');
5
  • When I tested your code the option key cb2_blog_home was being set as expected: 1, if checked. empty, if unchecked. Commented Feb 1, 2014 at 18:27
  • Rachel, can you tell me how you are able to check the key values in the post?
    – Scott B
    Commented Feb 2, 2014 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. Commented Feb 2, 2014 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
    Commented Feb 2, 2014 at 15:38
  • 1
    Any progress on that question? Debugging code available for later readers to give it a try?
    – kaiser
    Commented Feb 17, 2014 at 23:20

1 Answer 1

0

You use the type option to store your settings.

Customizer doe not store your default values in database until user click on save.

@see https://wordpress.stackexchange.com/a/247164/52167

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.