Wordpress HACK – How to widgetize your theme!

by max on Saturday, April 26th, 2008

Well, I had to widgetize my old theme today but it was pretty simple:

Make a file called functions.php in your theme directory. (if you don’t have one yet)

Add the following code and save the file:
if ( function_exists(’register_sidebar’) )
register_sidebar(array(
‘before_widget’ => ”,
‘after_widget’ => ”,
‘before_title’ => ‘

‘,
‘after_title’ => ‘

‘,
));
?>

Then add the following anywhere you want to add dynamic widgets:

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

<?php endif; ?>

You can actually put your existing code within the if loop OR you can also put it before or after.

Since I didn’t want to widgetize all existing stuff, I simply put it after all my existing code in my sidebar.

You can also create multiple dynamic widget locations simply by add numbers to the code like this:

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

<?php endif; ?>

Other Online Resources:

Widgetizing Themes by Automattic

Rate

1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

Categories: Blog, DIY, Educational, Hack, Misc, Web, Wordpress.
tokyoflash
ad ad
ad ad


20,000 GPS POI's $9.99

Related News and Resources

Other Interesting News From Our Friends

  • So that allows you to incorporate the widgets siderbar?
  • max
    Yup, basically that's what it does if your theme is old like mine OR simply doesn't support widgets.
blog comments powered by Disqus
If you like this post then please subscribe to my full feed RSS.

You can also subscribe by E-mail by filling out your name and E-mail below:

Name: Email:


Got a new hack, DIY, howto, or gadget? Tip us here.

Try Goohack to find a new Hack:


Featured Sites From Zedomax Blog Network