« Previous Next »

Is Your WordPress Theme Good Enough?

Are your widgets good enough? Following the release of the Tabbed Widgets plugin many people left comments saying that it doesn’t work with the theme they are using. And only then I realized how many themes do not take full advantage of widget functionality that WordPress provides by default. In this article I am going to show you how to fix them.

Widgets… hmm?

Let’s think of widgets as if they were plain cardboard boxes. And let’s suppose we both are in a room full of these boxes and we are trying to figure out what is inside each of the box just by looking at them. If they all are exactly the same size, shape and color, then there is no way to differentiate between them.

On the web everything is built from various markup and layout boxes. In case of WordPress widgets these are usually <div> elements that semantically donate a group of content. So if there are many widgets on a page, then each of them is inside the same <div> box and there is no way to telling them apart… unless unique names (indentifiers) and shared surnames (classes) are applied to each of them.

How the Tabbed Widgets Work

All the Tabbed Widgets magic is done by two amazing JavaScript functions — Tabs 3 by Klaus Hartl and Accordion by Jörn Zaefferer, which do the showing & hiding, and the dynamic transitions. Plugin’s PHP backend, however, places other widgets inside those tabbed and accordion blocks.

Now here is the problem — those Javascript functions need to know which of the fifty seven widgets in your blog’s sidebar are the tabbed ones. Even more — there might be one tabbed and one accordion type widget, right? So how can the scripts target them?

Unique identifiers or names and surnames, I say, is the answer. But the reality is — many themes do not use the WordPress built-in functionality that automatically generates these identifiers.

How to Fix Your WordPress Theme

First, find the place where your theme defines sidebar widgets. This is usually done in functions.php file in theme’s folder but it may differ. If you can’t find it, simply go through all the theme files and search for register_sidebar.

Find the line that defines the HTML element box in which all the widgets are placed. It should look something like this:

'before_widget' => '<div ... >',
'after_widget' => '</div>',

If it contains %1$s and %2$s then you should consider donating to the author of the theme for the great job. However, if they are not present, then replace it with

'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',

and WordPress will automaticaly replace %1$s with a unique identifier (name) and %2$s with a classname (surname) of each widget.

Anything Else?

Yes, if you find that %1$s and %2$s are missing, please contact the author of the theme with a link to this article. Thank you.

 

12 Responses

Andreas Viklund

Jul 27 at 1:37

#7497

Excellent, I have just tested the listed code and added it to those of my themes that are about to be updated soon. It will be added in all themes once they have all been updated, because this is a plugin that I know that a lot of people will want to use. :)

Kaspars

Jul 27 at 12:36

#7499

Andreas, great to hear that and thanks for the effort.

k|torz

Jul 28 at 8:40

#7501

Thank you very much for your explanation, all is working great now on my blog. Very good job!

k|torz

Jul 28 at 16:31

#7502

I spoke too speed… i think i have conflicts between jquery and prototype…

Kaspars

Aug 1 at 18:01

#7532

k|torz, try disabling the plugins which use some kind of javascript and see which one is causing the problem.

Jeffro2pt0

Aug 4 at 12:30

#7584

Glad to see you posted this article Kaspars. I’m getting ready to go through another redesign and if Tabbed widgets doesn’t work, I’ll be back to this page to implement your suggested fixes.

Nitin Srivastava

Aug 8 at 17:17

#7630

Hi,

This looks to be a wonderful plugin but unfortunately it does not work with Rebel Magazine Theme - http://www.wpthemedesigner.com.....ine-theme/.

Can you please help me to get your plugin working with Rebel Magazine Theme. My running website is - http://www.bhuspeaks.com

Regards,

Nitin

Kaspars

Aug 8 at 17:23

#7631

Nitin, you should contact the author of that theme and kindly ask him to correct the code that generates the code for the sidebar as described in this article. However, I suggest you try to fix it yourself, first.

Bernard Doddema, Jr.

Aug 11 at 18:51

#7679

This is where I get confused. It mostly reads as you’ve mentioned but adds the “li” as well as shown below:

[Code fragment removed because of incorrect formatting]

Is this ok or should I remove the “li”?

Thanks!

Kaspars

Aug 13 at 0:01

#7694

Bernard, you can leave the li there. I also suggest you read some basic tutorials about HTML and how it works in order to get a better feel why things should be done one or the other way.

wordpress hacks fan

Sep 25 at 15:04

#8083

nice plugin i just dicovered it now. I am curious to know if the plugin creates new tabs in accordance to your wordpress theme. anyway it is very nice above all for those blogs like mine which have got just one sidebar

Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> . If you post HTML or PHP code, don't forget to convert it to HTML entities.

Donate using PayPal If you find my WordPress plugins, themes and support useful, please consider donating. It is truly appreciated!


About the Author

Written by Kaspars who is a physics student and a graphic designer working on the web since 2000. Read more »

Articles & Bookmarks

From My Feed Reader

Interestingness (Bookmarks)

Around the Web

Delicious findings from around the Web that you may find useful:



Close
Powered by ShareThis