Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of how to add widget titles using the Customizer.
// 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
You can’t perform that action at this time.