How to register sidebars and widgets in WordPress

Lots of websites use a sidebar to keep content organized and more visible for it’s visitors.

What is a sidebar?
“Dynamic sidebar: A container for a set of widgets, which the user can set from the Widgets screen within the admin area.”
So basically a sidebar is a Widget container, and a widget is a small block that performs a specific function.Most of the themes already come with one or two sidebars, but maybe you need to add more (A sidebar can be use to place widgets without being in the “side” of the theme, it can be at the footer for example)

The proper way to register a sidebar is from you theme’s “functions.php” file, nowhere else. You need to use the “register_sidebar()” function.
In the next example you will register a sidebar named “third_sidebar”


add_action( 'widgets_init', 'my_register_sidebars' );

function my_register_sidebars() {

     /* Register the 'third_sidebar' sidebar. */

               'id' => 'third',
               'name' => __( ‘Third sidebar' ),
               'description' => __( 'A short description of the sidebar.' ),
               'before_widget' => '<div id="%1$s" class="widget %2$s">',
               'after_widget' => '</div>',
               'before_title' => '<h3 class="widget-title">',
               'after_title' => '</h3>'

     /* Repeat register_sidebar() code for additional sidebars. */


Basically, you need to place that code in your “functions.php” file.
Remember that each ID needs to be unique to the sidebar, ‘id’ => ‘third’,
The name is the human readable label that you will see in the WordPress dashboard, ‘name’ => __( ‘Third sidebar’ ),
It allows you to set a specific description for how the sidebar is used within your theme. ‘description’ => __( ‘A short description of the sidebar.’ ),

Hot to display the registered sidebar.
You will need to use the function called “dynamic_sidebar()” like this:

<div id="sidebar-third" class="sidebar">

     <?php dynamic_sidebar( 'third' ); ?>


And you can place it anywhere in your theme, although the code would be better in a file called sidebar-third.php.

So basically, to add a sidebar to your theme, you need first to register it, and then show the registered sidebar in any place in your theme, it can be more advance in case you need it, but these are the basic steps.

Looking for quality WordPress hosting? Check out Arvixe Web Solutions

Tags: , , , , , , | Posted under WordPress | RSS 2.0

Author Spotlight

Facu Puig

I make websites since 1997, I use Adobe since 2004 and Wordpress since 2007. Fascinated by design at the age of 8, thanks to my father, a multi award winner graphic designer.

One Comment on How to register sidebars and widgets in WordPress

  1. Noman says:

    Actually,I like single slidebar,I don’t like more than one slidebar.most of the theme offer single or multiple slidebar.few theme available without slidebar option.your tips really works.we can easily add more slidebar using your code.thanks for your tricks

Leave a Reply

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