WP Customizer radio buttons

Hi all,

at the moment, there’s no way you can add radiobuttons to the customizer screen in Pinegrow. A checkbox is difficult since it returns a value of 0 or 1 which sometimes is not adequate for use. Is it possible to use radio buttons in the customizer that return values like true or false?

Thanks. And stay safe.

At the top of the panel showing your files you’ll see a small rectangle with a down arrow.
Click this to reveal a library of page elements.
In the buttons section you’ll see “Radio button group”
Drag and drop this into your page.
You can return whatever value you want.
Checkboxes and Radio Buttons are just another way of selecting options.
one or more and only one respectively

Hi @mxs and @24degrees,

@mxs - @24degrees is asking about adding a radio button group to the WordPress customizer. The library would let you add them to your page, but not the customizer.

@24degrees - I’m not the in-house expert on PG WordPress, but as far as I know, right now you need some custom code to add radio buttons. You can do this through the “Add Customizer Control” WordPress action (not the smart action).


For “Control type” you select “Custom”, and then write a named PHP function and add it in the “Custom control” input box.
Something like:

function theme_radio_control($wp_customizer) {
$wp_customize->add_control( 'sample_default_radio',
   array(
      'label' => __( 'Standard Radio Control' ),
      'type' => 'radio',
      'choices' => array( // Optional.
         'captain-america' => __( 'Captain America' ),
         'iron-man' => __( 'Iron Man' ),
         'spider-man' => __( 'Spider-Man' ),
         'thor' => __( 'Thor' )
      )
   )
);
}

The items that normally go into the “add_setting” and the other parts of the “add_control” like description are entered into the upper input boxes (at least I think so for the additional parts of the “add_control”, might be wrong on this one).
Sorry! Not sure if this may be included in a future version or not.
Good Luck!! Reach back out if you need more help.
Cheers,
Bob

Bob

1 Like

Hi Bob, nice work, thanks you very much.

To make sure: in the custom control box, I would write theme_radio_control without rounded brackets, right?

Because I keep getting this error: Fatal error :

Uncaught Error: syntax error, unexpected ‘(’, expecting ')'

Thanks !

I think I’m forgetting something. I added the register stuff to your above function:

add_action( 'customize_register', 'theme_radio_control' ); 

Then:

image

Which results in the following error:

**Fatal error** : Uncaught Error: Class 'theme_radio_control' not found

We will keep on searching ! Next month, I have time to dive into PHP development again. Wordpress development will be a part of my study.

Thanks all.