• Resolved dtkerr

    (@dtkerr)


    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Matias Mann

    (@developress)

    I believe you cannot set a default text in a textarea in the customizer.

    The workaround would be to set the default text in the Theme Footer and hook a filter when changed in the customizer textarea.
    Makes sense?

    Thread Starter dtkerr

    (@dtkerr)

    Yeah, makes sense. And explains why the code wasn’t working for the textarea.

    Thanks for replying.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Defaults not working in Customizer with textarea’ is closed to new replies.