WordPress Theme Customizer & Theme Settings

In this article we will discuss about implementation of theme customizer in the WordPress theme, how to add settings for that, how to retrieve values and advance controls for of theme customizer in WordPress. Theme customizer enables functionality to make global settings that can be used at admin side or front end side.

There are many things we can implement in theme customizer. Below are few customizations we can do in WordPress.

1. Add Customizer Page

If you want to add theme customization facility to your theme then you can put below code in functions.php file.

2. Add Customizer Settings

Add settings section first to add any setting in customizer in functions.php file.

PHP

1

2

3

4

5

6

7

8

9

10

11

12

13

14

/**

* Add sections, settings, and controls to the theme customizer

*/

functiontheme_customizer($wp_customize){

$wp_customize->add_section(

'settings_section',

array(

'title'=>'Theme Settings',

'description'=>'This is a customizer settings section.',

'priority'=>12,

)

);

}

add_action('customize_register','theme_customizer');

Now we can add setting inside this newly made settings section.

PHP

1

2

3

4

5

6

$wp_customize->add_setting(

'copyrightbar',

array(

'default'=>'Write default copyright text here',

)

);

3. Add Control

A simple interface used to change a setting is called as control. Control can be added in settings by below code. We can use this text input for copyright text, website title, tagline or any kind of string that can be shown universally. If you provide this kind of field then you must do data sanitization to make database safe.