Bookmark, share, and hop your favorite sites with SiteHoppin Toolbar for Firefox!

Wordpress HACK - How to widgetize your theme!

Posted in Blog, Cool, DoItYourself!, Educational, Hack, Web, Wordpress by max on the April 26th, 2008 at 5:40 am

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 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...


Related Posts

Bookmark It!


|del.icio.us |Digg it |Netscape |SiteHoppin |Wagg It | Email this to a Friend Email This Post Email This Post

If you like this post then please subscribe to my full feed RSS. You can also subscribe by Email.

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

Search for a new Hack:



RSS feed

2 Comments »

Comment by GH3 Cheats
2008-04-26 11:18:33

So that allows you to incorporate the widgets siderbar?

MyAvatars 0.2
Comment by max
2008-04-27 02:50:19

Yup, basically that’s what it does if your theme is old like mine OR simply doesn’t support widgets.

MyAvatars 0.2
 
 
Name (required)
E-mail (required - never shown publicly)
URI

Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.