Widgets? How to make your theme Widget Friendly.

March 21, 2007

What are Widgets anyway? I asked myself this question quite a few times while searching through various WordPress blogs and continually seeing them referenced. It turns out that in a nutshell Widgets are little pieces of code that modify your default WordPress sidebar. Bloggers have been modifying their sidebars since discovering WordPress, but with Widgets this can be done easier, quicker and without ever touching a line of code. Want to display the latest three posts in your side bar – not a problem. Want to list all of your static pages, simple as well. All of this functionality is yours once you install one simple plugin. Oh and did I mention that you can do all of this without ever touching a line of code – I did, didn’t I?

First off you are going to need to install the plugin cleverly it’s called WordPress Widgets. Download and unzip the Plugin then install it . There is good documentation included with the Plugin and you should read that, but we all hate reading documentation so…

Make a directory called widgets in /wp-content/plugins/ then copy the 4 files from the plugin (delicious.php, gsearch.php, widgets.php, and rss.png) into that folder. Now activate WordPress Widgets by going to your WordPress admin -> Plugins and clicking the “Activate” button located next to “WordPress Widgets”.

When I installed widgets, I was already using a WordPress Theme that was safe for widgets. There are a ton of “widget friendly” themes out there, but if you happen to not be using one of them fear not, you can make your theme widget friendly. In the plugin zip there are two folders (classic and default) they each have a functions.php and sidebar.php file in them. If you are using defualt or classic for your theme – just uploading these two files will make your theme widget friendly but if you have modified your files in any way (like by including pages or manually hacking at the code) you will have to re-do your modification. If you are using some other non-widget-friendly theme, these two files will serve as the basis for your customization.

First off you will need to create (or edit if you already have one) a functions.php file in your themes directory (/wp-content/themes/your theme name/). Add this code to functions.php:

< ?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '', // Removes

  • ‘after_widget’ => ”, // Removes
  • ‘before_title’ => ‘

    ‘, // Replaces

    ‘after_title’ => ‘

    ‘, // Replaces
    ));?>

    Then within sidebar.php place the following code:

    < ?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else : ?>

    after

      That’s about it – upload your new side bar and functions file and you should be good. Rumor has it that in future WordPress releases, Widgets will be part of the core functionality. After using Widgets for a while, it’s easy to see why.

    Leave a Reply

    You must be logged in to post a comment.