We build easy to manage, secure and Mobile friendly Websites.

How To Add Textarea Field To WordPress Customizer


In this tutorial, I will be showing you how to add textarea field to WordPress customizer.

I have discussed about the parameters for add_setting() and add_control() functions in my previous tutorial.

We will be using the section created in the tutorial How To Add Text Field to WordPress Customizer to display this textarea in WordPress Customizer .

First lets create settings for textarea field

 $wp_customize->add_setting('themeslug_textarea_id', array(
    'default'        => '',
    'sanitize_callback' => 'sanitize_textarea_field'       
    ));

    

Then we create control for textarea field

$wp_customize->add_control('themeslug_textarea_id', array(
    'label' => esc_html__('Input Type: TextArea', 'themeslug'),
    'type' => 'textarea',
    'priority' => 2,
    'section'  => 'themeslug_section_id',
    'setting'  => 'themeslug_textarea_id',
    'capability' => 'edit_theme_options',
    ));	

Usage

<?php esc_html_e( get_theme_mod( 'themeslug_textarea_id' ) ); ?>

Leave a Reply

Your email address will not be published.