How to Create a widget area in wordpress theme

Before we start up with creating custom widget areas, you might want to know what are wordpress widgets? Custom widget area is uses to create a slot for widgets to be placed over them in the admin widgets area. There are a number of widgets that can be placed over these slots such as sidebar widgets for post categories, tag clouds, navigation, search, etc To appear, like in sidebar, in footer, in header, hence where ever their particular slots are defined. Custom widget area provides an easy-to-use drag and drop feature to wordpress users, where user can simply drag widgets from the available widgets to the widget area where they want the widget to be displayed.

You can find “Widgets” under the tab “Appearance” in Admin panel: Appearance -> Widgets

How to enable widget area in wordpress theme
Custom widget area is enabled from function.php that is available in the themes folder.
Add the following code in function.php to enable/register widget area in the wordpress theme:

if ( function_exists('register_sidebar') )
    register_sidebar( array(
   'name' => __( 'My Custom Widget Area - 1'),
   'id' => 'mycustomwidgetarea',
   'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
   'before_widget' => '",
   'before_title' => '

', 'after_title' => '

', ) );

How to add widget area in wordpress theme

Once you have enabled the function in function.php you can make any area as a widget area within a wordpress theme. Add the following code to the area ( sidebar, footer, header ) where you want the widget to to make a slot and add widget to it later from widgets setting panel:

NOTE: If you want more then one area to be widgetized at the same time, then you have to register sidebar in function.php more then once with different names and id’s

Now that you have enabled the widget area as well as created a slot for the widgets to be placed in, you can go to Appearance -> Widgets in admin panel and add the widgets to the slot you have just created.

Author: Ashif

Hi, my name is Ashif. I've been earning a living online since 2006 and love to share what I've learned. You can connect with me on Facebook, Twitter, YouTube and Google Plus. Don't forget to subscribe to my blog to keep up with my latest tips and tricks. You can also send questions in my mail.

Leave a Reply

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