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.

Comments

[...] 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. [...]

Sep 21, 2006

[...] 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. [...]

Oct 17, 2006

Hello!

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

Oct 26, 2006

Thanks heaps. This worked a treat for me.

Nov 5, 2006

how do i add functionality for TWO sidebars?

Nov 7, 2006

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

Nov 23, 2006

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.

Jan 14, 2007

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

\”Postin\” -Southern Verb, to post. lol

Jan 29, 2007

Scavella

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

Feb 17, 2007

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

Apr 12, 2007

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

Jul 12, 2007

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

Oct 14, 2008

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

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

You must be logged in to post a comment.