Theme Customization API
The Theme Customization API, added in WordPress 3.4, allows developers to customize WordPress’s Theme Customization admin screen. The Theme Customization screen (i.e. “Theme Customizer”) allows site admins to tweak a theme’s settings and see a preview of those changes in real time.
To add your own options to the theme customizer, you need to use a minimum of 2 hooks:
customize_register
This hook allows you define new Theme Customizer sections, settings, and controls.
wp_head
This hook allows you to output custom-generated CSS so that your changes show up correctly on the live website.
customize_register
This hook allows you define new Theme Customizer sections, settings, and controls.
The ‘customize_register’ action hook is used to customize and manipulate the Theme Customization admin screen introduced in WordPress Version 3.4. This hook is a component of the Theme Customization API.
function mytheme_customize_register( $wp_customize )
{
//All our sections, settings, and controls will be added here
}
add_action( 'customize_register', 'mytheme_customize_register
This hook gives you access to the $wp_customize object, which is an instance of the WP_Customize_Manager class. It is this class object that controls the Theme Customizer screen.
Generally, there are only 4 methods of the $wp_customize object that you will need to interact with inside the customize_register hook.
WP_Customize_Manager->add_setting() This adds a new setting to the database.
WP_Customize_Manager->add_section() This adds a new section (i.e. category/group) to the Theme Customizer page.
WP_Customize_Manager->add_control() This creates an HTML control that admins
can use to change settings. This is also where you choose a section for the control to appear in.
WP_Customize_Manager->get_setting() This can be used to fetch any existing setting, in the event you need to modify something (like one of WordPress’s default settings).