How to make your WordPress Theme Widget Ready

widget-ready-sidebar-2A widget ready Sidebar or widget ready theme or widgetized sidebars are most common with the wordpress themes since wordpress 2.0 came into existence. Widgetizing a sidebar comes really handy to change things in your sidebar quickly and easily without messing up with your wordpress themes code.

Most of the plugin too display data in form of widgets so as to make the the interface user friendly. Widgetizing the sidebar is really a simple  2 step process.

Step 1:
Open up the functions.php in your theme folder. If this file doesn’t exists then create a new file called functions.php and save it in your theme folder. Next add this code into the functions.php file and save it.

<?php
if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'sidebar',
        'before_widget' => '<li>',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));}
?>

The code is pretty self explanatory

function_exists check if a php function with the name register_sidebar exists , if yes then executes the code that follow.

Name stores the unique name of the sidebar (incase you may ahve multiple sidebars). Before_widget and after_widget determines the thml code to be executed before and after each widget respectively.  And before_title and after_title determines the code to be executed borde and after each widgets heading respectively.

Step 2:
In step one we have registered our sidebar in the wordpress code. That means that wordpress now knows that we have 1 sidebar in our theme. In this step we have to let wordpress know where our sidebar is located.

This time we will be using conditional tags to know if the wordpress version supports widgets or not (since versions below 2.0) doesnt support widgetized sidebars.  Open the file where the code of your sidebar is located.  Add this code where your sidebar exists

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar') ) : ?>
// write all the HTML code for the static sidebar widgets in case it doesn't support widgets
<?php endif; ?>

This means that any HTML code you write in between the 2 lines will be executed f the wordpress version i sless than 2.0 and if its 2.0 or greater then sidebar has to be controlled from the Manage Widgets Page i.e. /wp-admin/widgets.php

Please note that in second step !dynamic_sidebar(‘sidebar’) the sidebar is the name that we have used as the value of name => in the first step.

Related posts:

  1. Free WordPress Theme – WpTechTuts v1.0
  2. WordPress: Creating Custom 404 Pages
  3. Free WordPress Theme – CNAspire
  4. Free WordPress Theme – Inzpirashun
  5. Free WordPress Theme – Almost-Premium


The author is a small business owner himself specialising in Web Development. He runs Insight Studios which offers specialized Web Development, SEO Services and PPC Management for Small Business and SME thus ensuring growth and prosperity using the power of social media.

Share This Post

Related Articles

One Response to “How to make your WordPress Theme Widget Ready”

  1. Andy says:

    Hi i tried this but am still having trouble. I paid someone to design and upload my website and specifically said i wanted a bar on the side to put stuff like facebook posts etc. I didn’t know the terminology bu his was not done. i am being asked for more money to do that. basically i have got as far as making the widgets and sidebar appear on my theme. How to make them appear on my profile is beyond me. Can you help at all?

Leave a Reply

© 2012 MyGeekPal. All rights reserved. Site Admin · Entries RSS · Comments RSS
Designed by Insight Studios