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

How To Add Radio Field To WordPress Customizer


In this tutorial, I will be showing you how to add radio 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_radio_id', array(
    'default'        => '',      
    ));

Then we create control for radio field

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

Usage

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

Leave a Reply

Your email address will not be published.