Last active
February 24, 2017 12:35
-
-
Save seothemes/4e9985ed7b0754db24cff4db8f63456f to your computer and use it in GitHub Desktop.
An example of how to add widget titles using the Customizer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register demo widget area. | |
genesis_register_sidebar( array( | |
'id' => 'demo_widget', | |
'name' => __( 'Demo Widget', 'mytheme' ), | |
'description' => __( 'This is the demo widget area.', 'mytheme' ), | |
) ); | |
// Hook demo widget area before site footer. | |
function mytheme_demo_widget_area() { | |
// Get the widget title set in the Customizer. | |
$title = get_theme_mod( 'demo_widget_title', 'Demo Widget Title' ); | |
// Display widget area and print widget title before widget content. | |
genesis_widget_area( 'demo_widget', array( | |
'before' => sprintf( '<div class="demo-widget"><div class="wrap"><h2>%s</h2>', $title ), | |
'after' => '</div></div>', | |
) ); | |
} | |
add_action( 'genesis_before_footer', 'mytheme_demo_widget_area' ); | |
// Add Customizer section, setting and control. | |
function mytheme_customize_register( $wp_customize ) { | |
// Add Customizer section. | |
$wp_customize->add_section( 'widget_titles' , array( | |
'title' => __( 'Widget Titles', 'mytheme' ), | |
'priority' => 110, // Below 'Widget' section. | |
) ); | |
// Add Customizer setting. | |
$wp_customize->add_setting( | |
'demo_widget_title', array( | |
'default' => 'Demo Widget Title', | |
) | |
); | |
// Add Customizer control. | |
$wp_customize->add_control( | |
new WP_Customize_Control( | |
$wp_customize, | |
'demo_title', | |
array( | |
'label' => __( 'Demo Widget Title', 'mytheme' ), | |
'section' => 'widget_titles', | |
'settings' => 'demo_widget_title' | |
) | |
) | |
); | |
} | |
add_action( 'customize_register', 'mytheme_customize_register' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment