Widgetize your WordPress theme – a tutorial

If you have an WordPress account in wordpress.com you have probably seen that you can manage your sidebar dynamically. For this to work the current theme has to support widgets. Autmattic has come up with a plugin to enable this feature in a regular wordpress installation.

In order to widgetize your current theme all you have to do is register some functions and add a small amount of code to your sidebar.php. If you don’t have a functions.php in your theme create one and put this to it.


This is to register the sidebar as dynamic. Save and close we are done with functions.php

Let’s move on to sidebar.php and take a look how a regular file would look like.


To enable the widget support all we have to do is enclose the sidebar code in an if statement. Like this:


If you uninstall thw widget plugin or decide not to use it the default sidebar will be shown, the code within the if statement. Now go and install the widget plugin and you are set to go.

17 Responses to “Widgetize your WordPress theme – a tutorial”

  1. [...] I found Widget Enhanced Theme Switcher with its very cryptic information for a PHP dummy like me. I got some info at other places like here but never could get the thing to work. Looks like I might have to either get another theme that is Widget-ready or make due with only one theme and keep the blog that way. [...]

  2. silywily.com » Cool 2006/09/21 03:14

    [...] I love this theme, the shade of green used, the tree, sun and the grey background. The only problem for me tho, was that I love my widgets. My little toys, my widgets are and this them came sans Widgets. So I widgetized this theme. Not hard at all if you follow the code given HERE. [...]

  3. Catherina 2006/10/17 10:03

    Hello!

    Easy and simple tutorial! Worked great! Thanx! :D

  4. =corym= 2006/10/26 11:35

    Thanks heaps. This worked a treat for me.

  5. Gray 2006/11/05 16:25

    how do i add functionality for TWO sidebars?

  6. Eugen 2006/11/07 03:02

    oh man, where were you in former times? I would have used it 2 months ago ago. nevertheless thanksfor tutorial! :)

  7. Christopher Anderton 2006/11/23 08:26

    Tjena! Intressant tips! Får det dockinte att fungera alls. Använder en grovt modifierad RDC*0.7 tema.. Och när jag följer instruktionerna så försvinner hela min sidebar.

  8. cat litter 2007/01/14 08:53

    *taps fingers on desk and wonders why nobody is postin*

    “Postin” -Southern Verb, to post. lol

  9. Scavella 2007/01/29 16:20

    How would this be modified for a three-column layout? I have “sidebar” and “sidebar2″ in my sidebar.php.

  10. Dave 2007/02/17 09:14

    This is very cool – I had a template that was not widget friendly, and I did not want to change templates…with this tutorial and 5 minutes, I was able to get widgets to work. FANTASTIC job – thank you!!

  11. Anne 2007/04/12 13:57

    You know that thing about sense of humour.
    If you ain’t got it then you won’t get it.
    Keep it up…

  12. david 2007/07/12 23:03

    Super toto, facile et rapide : ça a marché !

  13. uploani 2008/10/14 10:55

    Çàíèìàþñü äèçàéíîì è õî÷ó ïîïðîñèòü àâòîðà http://www.fahlstad.se îòïðàâèòü øàüëîí÷èê íà ìîé ìûèë) Ãîòîâ çàïëàòèòü…

  14. [...] Widgetize your WordPress theme – a tutorial [...]

Leave a Reply

You must be logged in to post a comment.