Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

150 PART II • Designing and Developing WordPress Themes


Figure 6-5: The Theme Customizer as it looks when you’ve got the Twenty Fourteen theme activated.

ADDING YOUR OWN THEME SETTINGS
Adding new settings to the Theme Customizer isn’t all that complicated. To add a setting, you’ll
pass information to $wp_customize through the customize_register action. A
brand-new settings section will have you define (at least) a setting, a section, and a control. The
setting is the actual setting, the section is the box where the settings will be shown (such as the
Site Title & Tagline box), and finally, the control will do something with the setting. Just reading
about it like this makes the whole thing a bit hard to grasp, so let’s create a simple setting.

For this example, you’ll create some footer settings for the Kihon theme (http://tdh.me/
wordpress/kihon). First, you’ll create a simple text box for the footer copy and echo that
within the theme’s footer.php file. After that, you’ll create a setting for whether the credit links
for Kihon and WordPress should be shown.

Start with creating the text copy setting. For that, you’ll need a function for theme settings,
which goes in functions.php:

// THEME SETTINGS
function kihon_theme_settings( $wp_customize ) {
// You'll do stuff here soon
}
add_action( 'customize_register', 'kihon_theme_settings', 11 );

Everything you do will be passed to $wp_customize, which you’ll see in a little bit. The
settings and everything you need for them will be in kihon_theme_settings() function,
which will hook on to customize_register at the end, using add_action() as you’ll see.
Free download pdf