Recently noesh changed her template, just in case you hadn’t noticed. Thanks to WordPress’ flexibility in this regard, changing themes is pretty easy to do.

But along the way there were a couple of issues: The first one is, when changing, pretty much all of the custom code noesh manually added to the template was lost; the second one is the new template uses widgets. When the WordPress widgets are activated all the code that’s not part of the widget code – usually in the ‘sidebar’ file – is ignored.

As I figure it, there are a few ways to use the old code>

  • 1. Copy the XHTML code from the old template to the new template
  • 2. Look for updated versions of installed plugins and install those new versions, hoping they have widget functionality built into them
  • 3. Create new widgets from the existing plugins, modifying the plugin code to widgetize it.
  • 4. Use the old code in a widget-like way by way of an additional plugin or script

All of them have their benefits and their drawbacks. In my case I went for the last option, for it entailed the least time spent, because I don’t know much PHP to write plugins/widgets for wordpress and I’m not about to spend my energy learning how. Maybe some other time.

With this decided, I looked for a plugin that would let me do what I had in mind. After a while I found this plugin, which lets you use any PHP file in the template directory and add its contents as a widget in the configuration page.

Second step was to create a PHP file in which I put a fragment of code. In noesh’s case, it’s a call for the AJAX shoutbox which was originally on the sidebar code file:
< ?php jal_get_shoutbox(); ?>

In ruidoz’s case, it’s a call to the phrases script.

For all this to work, the file must begin with ‘widget_’ or ‘widget-‘ as the filename. Upload it to the server and save it on the active template directory. If it’s put somewhere it just won’t work. After that the necessary amount of theme widgets have to be activated on the widget configuration page. Read the plugin instructions for more details.

With these steps all those plugins that had to be called from the template sidebar file can be added as widgets without having to muck around the code itself. Helps a lot with themes that had the widget coded added to them and with plugins that don’t have widget functionality built into them yet.

This is great for PHP… but what if you had a bit of XHTML code? Not to worry; all that needs to be done is to add it as a text widget. This is useful for fragments of code like a flickr badge. For this the theme widgets plugin doesn’t have to be installed, since the function is included with the widgets plugin itself. For example, noeshtiosita’s badge now looks like this:
HTML Fragment.

The total time spent? Just about an hour and a half, which – for the effort – is nice. Another good thing is it lets you change theme quicker and easier since no coded needs to be added or removed from the template code. Just move the ‘widget_’ or ‘widget-‘ files to the new template’s directory and reactivate them at the widget configuration page.

Now, keep in mind this is pretty much a temporal solution until most plugins have widget funcions implemented. Until then, this is something to do to avoid code headaches.

2 thoughts on “Widgetize”

  1. Please improve your knowledge with more study……..is the best you can do….

  2. I’d say, “Please, Alfredo, improve your grammar with more study; IT’S the best you can do, lol.”

Comments are closed.