Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
I've never heard of this happening. Is this one of the core widgets? –  John P Bloch Dec 14 '10 at 21:53
    
    
Not my widget. But I needed this functionality :) –  Scott B Dec 14 '10 at 22:00

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
    
Thanks MathSmath. Here's the widget > wordpress.org/extend/plugins/related-posts-by-category-widget –  Scott B Dec 14 '10 at 22:00

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.

share|improve this answer

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.

share|improve this answer
    
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 Dec 15 '10 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. –  Denis Dec 15 '10 at 11:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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