0

I've found a widget that I need to add to more than one sidebar widget area. However, apparently its been coded so that once you drag it from "available widgets" over to a sidebar widget, it disappears from the "available widgets" listing.

I'd like to use it in more than one sidebar. What determines this in the widget code?

3

3 Answers 3

5

Sounds like your widget written in the old (pre 2.8) style rather than using the widget class. If that's the case, you need to add code in a few different places to handle multiple instances (it's not a simple option you can turn on or off).

Check out this page in the Codex, and this article about creating a multiple instance widget linked from it.

Depending on the complexity of the widget, it might be easier to just rewrite it using the Widgets class (examples are provided in that Codex article). It handles multiple instances automagically.

1
2

It's due to how the widget is registered, the older register_sidebar_widget function didn't support creating multiple instances. That function is now deprecated and has been replaced by register_widget which allows creating multiple instances.

http://codex.wordpress.org/Function_Reference/register_sidebar_widget - old
http://codex.wordpress.org/Function_Reference/register_widget - new

I think the Widget API gives a decent enough example of a multi instance widget.

So in other words, just update your widgets to use the newer widget registeration method.

1

You're understanding it correctly. The API doesn't allow the same widget to be used in multiple sidebars. This is due to the way widgets are deleted. If it were allowed, WP would end up deleting the same widget from all sidebars if you delete it from a single one; it would also leave dead widget references in sidebars.

2
  • Hi Denis, I think I'm misunderstanding your point. For example, I can drag as many text, links, or category widgets as I want over to my sidebars. Each one shows up as a discrete instance of the original. What am I missing?
    – Scott B
    Commented Dec 15, 2010 at 0:24
  • Indeed, but what's happening underneath is, WP is creating a new instance of these widgets using ajax when you do, and each instance of these widgets can only exist in a unique sidebar -- for the reason I highlighted in my answer. Commented Dec 15, 2010 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.