Adding a custom section in the WordPress Theme Customizer

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

In this tutorial, we add the “Copyright” section to the WordPress Theme Customizer that is displayed when user goes to “WP Dashboard -> Appearance -> Customizer” …

customizer section

This section has a textbox “control” labeled “Copyright Text” where user can enter a value to save to the “footer_copyright” setting …

customizer control

In order to create this, we have to “require” the file “customizer.php” in theme’s function.php so that we can use the WordPress Customizer API.   The Twenty Fifteen theme happen to already have this require statement as well as the customizer.php.

So we next add function “mytheme_customize_register” to the “customizer_register” hook …

customizer code

We pass into this function $wp_customize so that we can use it to “add_section”, “add_setting”, and “add_control”.  The add_control takes one of the classes listed here depending on the type of control you want.  We want a textbox, so we use WP_Customize_Control.

The control references the section and settings that we just added.

At this point, the Customizer interface in the Dashboard is working and the setting value can be saved.

To retrieve and use the saved value in our template, we add the following to the footer.php template code …

using wordpress customizer value

Calling get_theme_mod passing it the setting name will retrieve the value for you.