Defaults not working in Customizer with textarea
-
Hi there,
I’m currently experiencing an issue with the default setting when adding a textarea to the customizer. To add the setting, I use the following code with a default of ‘Copyright.” set:
$wp_customize->add_setting( 'copyright_text' , array( 'default' => esc_html__( 'Copyright.', 'themename' ), 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_textarea_field', ) );To add the control, I use the following code:
$wp_customize->add_control( 'copyright_text_control', array( 'label' => esc_html__( 'Copyright Text', 'themename' ), 'description' => esc_html__( 'Insert copyright text.', 'themename' ), 'section' => 'custom_footer_settings', 'settings' => 'copyright_text', 'priority' => 20, 'type' => 'textarea', ) );Then to call it on the front end, I use the following code:
<?php echo get_theme_mod( 'copyright_text', 'Copyright Test' ); ?>Every thing works as expected, except the default text. If I enter text in the textarea and click Publish, the text appears on the front end of the site, but the default text won’t.
My understanding is this:
'default' => esc_html__( 'Copyright.', 'themename' ),– This is what is displayed in the Customizer panel when it loads (if no custom text has been set).<?php echo get_theme_mod( 'copyright_text', 'Copyright Test' ); ?>– The ‘Copyright Text’ text is what is displayed on the front end (if no custom text has been set).I tested this exact code with just a text field (not the textarea) and every thing worked, including the defaults. I just can not get the defaults to display in either the Customizer panel or the front end when using a textarea.
Do I need to do something different with the textarea?
The topic ‘Defaults not working in Customizer with textarea’ is closed to new replies.