Skip to content

Instantly share code, notes, and snippets.

@ajskelton
Last active May 14, 2024 04:54
Show Gist options
  • Save ajskelton/c29037a88605626ce6aba199b6b8566b to your computer and use it in GitHub Desktop.
Save ajskelton/c29037a88605626ce6aba199b6b8566b to your computer and use it in GitHub Desktop.
Add a Textarea field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_textarea_setting_id', array(
'capability' => 'edit_theme_options',
'default' => 'Lorem Ipsum Dolor Sit amet',
'sanitize_callback' => 'sanitize_textarea_field',
) );
$wp_customize->add_control( 'themeslug_textarea_setting_id', array(
'type' => 'textarea',
'section' => 'custom_section', // // Add a default or your own section
'label' => __( 'Custom Text Area' ),
'description' => __( 'This is a custom textarea.' ),
) );
@erikyo
Copy link

erikyo commented Sep 9, 2019

the correct sanitization for a multiline string is 'sanitize_textarea_field'

https://developer.wordpress.org/reference/functions/sanitize_textarea_field/

@LucaThemes
Copy link

I have a problem, when I put it to use 2 times I get error

Make sure the themeslug_textarea_setting_id is unique for every setting you add

@TutsInsider
Copy link

i have used it, but there is a problem, when i write css code inside textarea, it does not update in realtime on preview pane, instead refreshing is needed to view changes. Further, i have also used th postMessage method for transport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment