March 17, 2009

How to widgetize a WordPress blog theme


Okay, if you’re new to WordPress, more than likely all of the themes you are looking at using are widgetized. For that special occasion that your WordPress blog theme isn’t widgetized, here’s a simple way of how to hack your theme, and with just a little bit of code, you can widgetize your theme.

Here’s what the official page from Automattic says:

Instead of register_sidebar() you should use register_sidebars(n) where n is the number of sidebars. Then place the appropriate number in the dynamic_sidebar() function, starting with 1. (There are several other ways to use these function. See the API). You can even give your sidebars names rather than numbers, which lets you maintain a different set of saved sidebars for each theme.

You edit this in the functions.php file. If you don’t have a functions.php file, then you probably don’t have a widgetized theme. Here’s an example of some code that you could put in your functions.php file:

if ( function_exists(’register_sidebar’) )

Then, right beneath the <ul> tag in the sidebar.php file, add this little piece of code:

<?php if ( !function_exists(’dynamic_sidebar’)
|| !dynamic_sidebar() ) : ?>

Then, right above the closing </ul> tag, put this code:

<?php endif; ?>

Pretty simple huh? Now that old-school WordPress theme that you are using is completely widgetized and customizable!

Previous Post and Next Post

Try HostGator Webhosting for 1 cent for the 1st Month Click here and enter "wordpress"

Leave a reply

* means field is required.