Add sidebar widget support to your WordPress theme

First, let’s go to your theme’s sidebar.php. Add the following where you want your sidebar widgets to be listed:

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

Then, add this to your functions.php:

/*  Register sidebars
/* ------------------------------------ */
function alx_sidebars()	{
	register_sidebar(array( 'name' => 'Primary','id' => 'primary','description' => "Normal full width sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>'));
}
add_action( 'widgets_init', 'alx_sidebars' );

That’s all you need to make your theme widget-ready. Give it a go!

Function reference: register_sidebar

3 Responses

  1. thefeldkircher says:

    Hi

    function missing open curly brace.

  2. Dzung says:

    Hi, thanks for tout sharing, but i can’t add sidebar for my single product wordpress. :((

Leave a Reply to Alexander Cancel reply

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