Extend Customizer Options To Include Radio Image Option

WordPress allows you to customize the customizer options as required for your site. You can do whatever you like to extend the WordPress Customizer options. However, here we will study about how to extend it to add the radio image option in the Customizer.

WordPress Customizer

So, first of all let’s have a surface look on the WordPress Customizer. So, what is WordPress Customizer Options really? Well, it is the feature within WordPress from which within, you can add the theme options in your theme and make the WordPress theme dynamic.

As for eg: let us build the WordPress magazine theme, in which you may want or do not want to add the sticky menu in your site. So, how about adding up this feature into your theme? Well, its not hard since you are on good place since using WordPress for same. As we told earlier, this, WordPress Customizer Options helps you to add such feature within your theme.

You can learn on more about the Customizer Options here.

Extend Customizer Options To Add Radio Image Option

Since we now know some knowledge on the WordPress Cutomizer, now let’s move ahead and create the Radio Image Option within your theme via extending the Customizer API.

First of all, to use the Customizer Options, you need to hook it to the proper WordPress hook, ie, in the customize_register hook. So, let’s move ahead and create the function which carries this customizer options within your theme.

In your file, say it customizer.php, you need to add the function as below to register the customizer options into your theme:

Now, after you have added that above PHP code into the theme’s file then, let’s move ahead and extend the WordPress customizer site to include the radio image option within it. First of all, what you need to know is, you need to extend the WP_Customize_Control class to extend the Customizer options. So, let’s extend it to include the custom radio image option control.

For this, let’s create a new class¬† Theme_Slug_Image_Radio_Control to extend the above class WP_Customize_Control. Now, since the controls are always rendered hence, we need to extend the render_content()¬†function, which resides within this class. So, let’s move ahead and extend this class about adding the radio image option within customizer option.

Now, you just need to add the below PHP code within any of the included PHP files:

Adding Required CSS And JS To Display/Function The Radio Image Option Properly

As we covered up the PHP code to extend the customizer options to add the radio image option within customizer options, now we also need to apply the CSS and JS to function it properly. So, to apply the required CSS and JS effect for the desired effect, you can create a new function and then hook that to the customize_controls_enqueue_scripts function, ie, enqueue CSS and JS for the radio controls in the mentioned WordPress hook.

Here, in the enqueued CSS file, you can add the below CSS code within it to apply some designs:

And for the JS file, you can add the below JS code for desired changes, ie, clicking on the radio image and change the options as required:

Now, if you followed this tutorial along, you are now ready to use this radio image option within the customizer options, which we will cover below.

Use the Radio Image Options In Customizer

Now, since you learned about extending the customizer option to include the radio image option, now, you can apply the extended customizer options as below within the above created function, ie, inside the function theme_slug_customize_register as below:

Here above, the main extending part is $wp_customize->add_control(new theme_slug_Image_Radio_Control($wp_customize, 'theme_slug_default_layout', array())); from which, the extended customizer options will take part.

Output Of The Radio Image Option Customizer Options

You can see the output of the extended radio option as below:

You may also want to read:

  1. Integrate Bootstrap NavBar 4 Into WordPress Theme
  2. Selective Refresh In Customizer Options
  3. Enqueue Custom CSS And JavaScript Libraries In WordPress


If you have successfully followed this tutorial and have became successfully able to implement the radio image option within your theme then, we can assume that you are now more familiar on this than before. But, if you are still confused about how to do it and want more help on this then do drop the comment below in the comment box and we will follow it up.

, , , , , , , , , , , , , , , , , , ,

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply