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

How to Add Select Field To WordPress Customizer


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

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

First let create settings for select field

$wp_customize->add_setting('themeslug_select_id', array(
    'default'        => '',
           
    ));

Then, we create control for select field


    $wp_customize->add_control('themeslug_select_id', array(
    'label'      => esc_html__('Input Type select:', 'themeslug'),
    'type' => 'select',
    'choices' => array(
        'default' => __('Default'),
        'one' => __( 'One' ),
        'two' => __( 'Two' ),
        'three' => __( 'Three' ),
    ),
    'priority' => 5,
    'section'    => 'themeslug_section_id',
    'setting'   => 'themeslug_select_id',
    'capability' => 'edit_theme_options'
    ));	

Usage

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

Leave a Reply

Your email address will not be published. Required fields are marked *