08 Apr Add Custom Widget ‘Sidebar’ in WordPress
//Add to functions.php
function custom_widgets_init() {
register_sidebar( array(
'name' => 'Your Sidebar Name',
'id' => 'your-sidebar-name',
'before_widget' => '<div class="your-sidebar-name">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sidebar-title-name">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'custom_widgets_init' );
//Add to a template
if ( is_active_sidebar( 'your-sidebar-name' ) ) : ?>
<div id="your-sidebar-name" class="your-sidebar-name" role="complementary">
<?php dynamic_sidebar( 'your-sidebar-name' ); ?>
</div>
<?php endif; ?>