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

(avery) #1

154 PART II • Designing and Developing WordPress Themes


The following is the complete code for the theme settings:

// THEME SETTINGS
function kihon_theme_settings( $wp_customize ) {

// Add kihon_footer section footer settings
$wp_customize->add_section( 'kihon_footer', array(
'title' => 'Footer Details', // Title of section
'description' => 'Customize your site\'s footer copy.', // Description
) );

// Add setting for kihon_footer_copyright
$wp_customize->add_setting( 'kihon_footer_copyright', array(
'default' => '© '. get_bloginfo( 'name' ),
) );

// Add control for kihon_footer_copyright
$wp_customize->add_control( 'kihon_footer_copyright', array(
'label' => 'Text in the footer',
'type' => 'text',
'section' => 'kihon_footer', // Add to section kihon_footer
) );

// Add setting for kihon_footer_credits
$wp_customize->add_setting( 'kihon_footer_credits', array(
'default' => 0,
) );

// Add control for kihon_footer_credits
$wp_customize->add_control( 'kihon_footer_credits', array(
'label' => 'Hide credits from the footer',
'type' => 'checkbox',
'section' => 'kihon_footer', // Add to section kihon_footer
) );
}

add_action( 'customize_register', 'kihon_theme_settings', 11 );

There are a lot of things you can do with the Theme Customizer API, and a lot of various
settings for your sections, settings, and controls. As always, the Codex offers both references
and introductions on how to do more with this particular technique at https://codex.
wordpress.org/Theme_Customization_API.

THEME OPTION PAGES
Sometimes, you just need a place to provide the necessary data to make the site behave like
you want it to, and the Theme Customizer might not fit your needs.
Free download pdf