$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Changing Customizer Select To Checbox, But Retaining Classes|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Changing Customizer Select To Checbox, But Retaining Classes

matteradmin12PV0评论

On a custom theme I had made, I had some options like so:

$wp_customize->add_setting('swag_header_display_homepage', array(
        'default' => 'header-display-homepage-yes'
    ));
    $wp_customize->add_control('swag_header_display_homepage', array(
        'label' => 'Display Header On Homepage',
        'section' => 'swag_header_display_section',
        'type' => 'select'
        'choices' => array(
            'header-display-homepage-yes' => __('Yes'),
            'header-display-homepage-no' => __('No')
        )
    ));

The choices you see there end up being classes that get added to the header.

I tried changing it to a checkbox instead of dropdown selection by changing 'type' => 'select' to 'type' => 'checkbox'. Although, I know "choices" are for dropdown selections. How can I keep the classes when changing it to a checkbox.

I tried

'std' => array(
            'header-display-homepage-yes' => __('1'),
            'header-display-homepage-no' => __('0')
        )

Which I know is wrong on so many levels. How can I do it properly, or is it even possible?

On a custom theme I had made, I had some options like so:

$wp_customize->add_setting('swag_header_display_homepage', array(
        'default' => 'header-display-homepage-yes'
    ));
    $wp_customize->add_control('swag_header_display_homepage', array(
        'label' => 'Display Header On Homepage',
        'section' => 'swag_header_display_section',
        'type' => 'select'
        'choices' => array(
            'header-display-homepage-yes' => __('Yes'),
            'header-display-homepage-no' => __('No')
        )
    ));

The choices you see there end up being classes that get added to the header.

I tried changing it to a checkbox instead of dropdown selection by changing 'type' => 'select' to 'type' => 'checkbox'. Although, I know "choices" are for dropdown selections. How can I keep the classes when changing it to a checkbox.

I tried

'std' => array(
            'header-display-homepage-yes' => __('1'),
            'header-display-homepage-no' => __('0')
        )

Which I know is wrong on so many levels. How can I do it properly, or is it even possible?

Share Improve this question asked Mar 5, 2019 at 21:48 XarcellXarcell 1035 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Checkboxes would be the incorrect choice for a yes/no option, because you'd be able to select both options. You want radio buttons. Just change type to radio. Radio buttons also support choices, so you won't need to change that part.

Post a comment

comment list (0)

  1. No comments so far