Need help setting default setting value for radio button in theme customizer

It is a long question but it is possible for some developers I would like to give this answer.

Example: I have two choose for my home layout Grid and List and I prefer Grid is default choosing. I should add default value in add_setting simple like this 'default' => 'grid'.

$wp_customize->add_setting('yourtheme_home_layout_style', 
    array(
        'sanitize_callback' => 'sanitize_text_field', 
        'default' => 'grid'
    ));
    $wp_customize->add_control( 'yourtheme_home_layout_style', array(
        'section'               => 'yourtheme_home_layout_section',
        'label'                 => __( 'Layout Style', 'textdomain' ),
        'type'                  => 'radio',
        'priority'              => 1,
        'choices'               => array(
            'grid'                  => __('Grid', 'textdomain'),
            'list'                  => __('List', 'textdomain'),
        ),
    ));

Leave a Comment