Quantcast

Customizing WordPress Theme Sidebar

With a WordPress Sidebar Template, we need to make sure it’s “widgetized”. In this tutorial, we would use 2 widget areas, since with it the code can be used with both 2 and 3 column themes. The widget areas would be registered in the functions.php code as follows:


Now we’ve got two widget areas: Primary Widget Area and Secondary Widget Area. There’s no point naming them Primary Sidebar or Secondary Sidebar. In some layouts they might not even be sidebars—but they’ll always be widget areas. Now, in functions.php we’re going to add two more custom code snippets.

Now, we’re going to pre-set our default widgets: The Search, Pages, Categories, Archives, Links and Meta Widgets. We won’t be coding them in manually to sidebar.php. We’ll be telling WordPress to add them to our dynamic widget area in the settings:

Now, in our Primary Widget Area (primary_widget_area) we’ve got the Search Widget, the Pages Widget, the Categories Widget, and the Archives Widget. The Secondary Widget Area (secondary_widget_area) has the Links and Meta Widgets. They’re all loaded up there in our WordPress options, ready and waiting.

Now, through the following code, we’re going to create a new conditional that will check to see if there are any widgets in a given widget area:

With our dynamic widget areas registered and pre-set widgets, our Sidebar Template is going to be one of the simplest templates you’ll ever see. But remember, we’re also going to want to wrap our sidebars in an IF statement using our new conditional is_sidebar_active().

Now if you go into the widget admin page and pull all those widgets out of any one of those widget areas, the conditional statement guarding the markup will fail. And that’s all about editing the Sidebar; no other manual editing is required.

Looking for a quality hosting service? here are a few I suggest.
BlueHost | HostGator | Media Temple
Admin
Admin
Ali has been an entrepreneur in web, video and related technologies. Having worked with many business across the globe, Ali stands truly a great pillar in the business working with him.