How to create a Widget Area in WordPress theme

Widget Area is a part of a WordPress theme structure where Widgets can be added.Widget area is normally in right side of main content area or in left side of it.It can be created in header area of website,in footer area of website or in the middle of posts.Almost anywhere you want.
Widget areas also referred as Sidebars.

To add a Widget Go to Appearance > Widgets and Drag a Widget to a Widget Area.Here you can add available Widgets.

Most new themes are widgetized now.check your theme Widgets Section for that.Plugins also create Widgets to display contents or some special features.

So, Let’s start and create a widget area

Creating a Widget Area

There are two steps to create a Widget Area.

1. Registering a Widget Area

Add following code in your theme’s functions.php file.

Note: I have added prefix  wpgyan_  to function name at two places at top and at bottom.You can change to a prefix of your choice.

2. Display Widget Area

To display Widget Area add following code to location of your choice in your theme file.

header_sidebar is id of Widget area in Step 1.

To Preview  new created Widget Area you can go to Appearance > Widgets.There Must be a Widget area of name “Header Sidebar”.

Multiple Widget areas can be registered using above code.Just use different id for each Widget Area.

Related posts

Leave a Comment