3

I'm working on a custom site, doing all my work in a child theme. I need to add one variable, slider speed, to the customize control system. I've been able to modify the custom controls via the following additions to my child-theme functions.php file:

function Primm_customize_register( $wp_customize ) {

$wp_customize->add_section( 'primm_section' , array(
    'title'     => __( 'Primm Home Page', 'Divi-child' ),
    'capability' => 'edit_theme_options',
    'description' => 'Setting options for home page'
) );

$wp_customize->add_setting(
   // ID
   'primm_slider_speed',
   // Arguments array
   array(
       'default' => '5000',
       'type' => 'option'
   )
);
$wp_customize->add_control(
    // ID
    'primm_slider_speed',
    // Arguments array
    array(
        'label' => __( 'Cycle Time on Slider (0.001 secs)', 'Divi-child' ),
        'section' => 'primm_section',
        'type' => 'text',
        // This last one must match setting ID from above
        'settings' => 'primm_slider_speed'
    )
);
}
 add_action( 'customize_register', 'Primm_customize_register' );

That stuff seems to work well. I can make changes on the admin custom menu, save the settings and see that a value seems 'set'. On the other hand, I'm attempting to call that variable from within my home.php file.

 $slider_timing= get_theme_mod('primm_slider_speed');
 echo("Slider Timing: ".$slider_timing);  // test only
 var_dump($slider_timing);

total fail. This is my response:

 Slider Timing: bool(false)             

Been working on this for hours. I'm missing something, but its just not clear to me what. Note: my child theme is "Divi-child" (based on the directory name at root/wp-content/themes/Divi-child ) Anybody been here before on the general topic of Wordpress Theme customizer? How do I allow admin users to set a value in 'storage' and then retrieve it again later? Many thanx, Zip.

1

I made one change...

 $wp_customize->add_setting(
        // ID
        'primm_slider_speed',
        // Arguments array
        array(
            'default' => '5000',
            'type' => 'theme_mod'    <-- made change right here.
        )
     );

'type' = 'option' just didn't work. 'type' = 'theme_mod' totally nailed it.

Option set manually to 6200, hit save. Refresh home page. Output now:

 Slider Timing: 6200string(4) "6200" 

Big Ouch... the choices for type = 'option' or 'theme_mod' followed by my later call to get_theme_mod()... Which one do you think will work? (hint: duh)

Info provided here for anybody who may experience the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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