Register New Sidebars in WordPress

Today, I’ll show you how to register new sidebars in WordPress, which can be used to add new widgets areas for use across a website such as in custom page templates, footers and just about anywhere.

It’s a 2 step process, so let’s get started on step 1.

1. Register the sidebar

In either functions.php or a custom plugin, register a sidebar with the following:

function pro_sidebar_init() {
register_sidebar( array(
'name' => __( 'New Sidebar', 'pro' ),
'id' => 'new-sidebar',
'description' => __( 'The new sidebar description to explain where it is located.', 'wpb' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'pro_sidebar_init' );

 

2. Add to PHP template

You can add this new sidebar, (once content had been added in Widgets) by placing this in the desired location:

<?php if ( is_active_sidebar( 'new-sidebar' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'new-sidebar' ); ?>
</div>
<?php endif; ?>

and you will see the new sidebar with custom content in the location. Hope this helps!

Useful post? Share it

0 comments on “Register New Sidebars in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *