Available at wordpress now – This plugin allows you to use any widget as a shortcode in a page or post with any theme. While many plugin authors do provide a widget and a shortcode, not all do. With this plugin there is no need to use the hybrid theme or create a special page template just to use a widget in a page or post.
For example
- [do_widget id=tag_cloud-2] will show the second tag cloud widget
- [do_widget "query posts"] will allow you to have a selection of posts listed in your page. The plugin uses a dummy sidebar called “shortcode” which allows one to use the widgets user interface to specify the custom settings.
The shortcode sidebar is a named widget sidebar only used to set up the widget settings.
Warning: Themes with numbered (or totally unnamed sidebars) do not work well this. Somehow since the plugin is creating the shortcode sidebar rather than a theme (and plugins seem to run befor the theme code), wordpress allocates it the number one slot. Named sidebars are okay, but others relying on being no.1 or the one and only are pushed out. Fixed in version 1.12.
Primarily I have in mind that one would want to list posts by excerpts for a category or a tag group within a discussion of the subject. Thus one could have multiple portfolio pages. This is achieved using Justin Tadlocks query posts widget with this do_widget shortcode. One could also try using the template tags shortcode plugin also by Justin Tadlock to achieve similar functionality. The differences with this plugin are
- any widget could be used (as opposed to template tags)
- no special UI (User Interface) needed as each widget’s own UI is used to set any settings
I’d love to hear other ways that people might decide to use this plugin.
Download: amr_shortcode_any_widget
Related posts:
- The “shortcode any widget” handles multiple instances The shortcode any widget plugin can reference multiple instances of the same widget individually by targeting the instances unique id. ...
- Widget as shortcode – tips Want to keep the widget title to identify it from other instances of the same widget, but want to hide...
- Initial content for a new page or post – wordpress pleasant surprise How to create a link to the add new page or post with default starting content...
- Subscribe2 widget markup and css Please refer to updated instructions. The wordpress subscribe 2 plugin is great. Version 4.9 just released – a wonderful alternative...
- Widgetized headers and footers? Dynamic (widgetized) Sidebars are great, but would you not like to have a dynamic header and footer in your theme...








40 Comments
October 14th, 2009 at 8:30 am
Nice idea. What are the primary use cases you are targeting?
October 26th, 2009 at 1:00 am
I’m using WP 2.8.5 and the Thematic Framework.
I get the following error trying to use a Query Posts Widget in my page with the following shortcode [do_widget "query posts"]:
Warning: array_intersect() [function.array-intersect]: Argument #2 is not an array in /*/*/*/*/wp-content/plugins/amr_shortcode_any_widget.php on line 57
line 57:
/* get the intersect of the 2 widget setups so we just get the widget we want */
$wid = array_intersect ($_wp_sidebars_widgets[$sidebarid],$widget_ids );
if ($debug) { echo ‘Chosen Widget ids in Chosen sidebar’;print_r($wid);}
I also wan’t to ask how can I use more than one instace of the same widget, since they have the same name.
Thank you,
October 26th, 2009 at 3:49 am
Hi marcello,
a quick reply while on the run… Clearly looks like I need to error trap a bit more. Will also write up more.
Try entering Query Posts ie with the capitals. [do_widget "Query Posts"]
This will grab whether instances have been defined in the shortcode sidebar.
To access only ONE, view source to find the query post id and enter [do_widget id="query-posts-n"] .
Hope that makes sense for now.
October 26th, 2009 at 4:26 am
Hey! thank you.
Works with [do_widget "Query Posts"] but it doesn’t work with [do_widget id="query-posts-n"], it doesn’t return any errors but renders no content. I inspected the widget and got it’s id that’s clearly visible in the widgets panel HTML code and when it renders correctly in the page.
any clue?
I’ll be using Display Widgets plugin to restrict appereance in the meantime.
Thank you.
October 26th, 2009 at 5:47 am
Hi Marcelo, Sorry if in my rush I was not clear enough, Yes – Replace “n” with the number of the widget id.
IE: you need exactly the widget id that shows in the html source to isolate the exact instance if you are using a widget multiple times.
It seems from your comment that you had worked that out but did not realise that that was what I meant.
Do you have it working now?
October 26th, 2009 at 5:53 am
Well – my requirement was to use query posts in a way that would work across themes – ie I did not want to have to write theme templates that did what query posts does.
QP did not have a shortcode and while I could modify it, I prefer to stay with the upgrade path.
Many author seems to deliver a widget without also doing a shortcode – it is quite easy to offer both callingthe same code.
…and so “do widget” was born. It can be used for any widget since it is essentially capturing the output of the widget function and returning that as the shortcode function result.
October 26th, 2009 at 7:12 am
Hi.
I got it working perfectly with the [do_widget "Query Posts"] but not with [do_widget id="query-posts-n"] shortcode.
I replaced the n with the ID i got from inspecting the widget with firebug, in my case it’s query-posts-4, but it doesn’t work that way even if I have only this one widget. It returns empty content, but no errors.
Sorry if I wasn’t clear. But if it works for you, it’s sure something to do with my setup or a conflict with another plugin. (maybe).
cya
November 19th, 2009 at 2:16 pm
Hi Anna-Marie,
Nice plugin and it does what it “says on the tin”. My only issue with it is that it seems to interfere with the other Sidebars on my site. It’s as though, even though the sidebar isn’t displayed by the theme (Atahualpa342), the sidebar grabs the formatting done for the first sidebar on my site. So effectively side bar one loses formatting, side bar two uses formatting of side bar one, side bar three uses formatting of side bar two and so on (I have 5 sidebars).
I haven’t had time to properly investigate (mostly due to a 3 year old toddler running around wanting to play at pirates!), my initial thought is that the sidebar registered for the plugin might need to be in functions.php
Thanks again for the plugin. I have a feeling its gone to be exactly what I need to work with, as you suggested, the Query Posts plugin
Adrian
November 20th, 2009 at 12:55 am
My primary use was to avoid creating a theme dependant template to list a subset of posts. So I wanted the widget “query post” functionality in a page – this would then work no matter what theme I switched to.
As far as other uses go…. anything is possible. Ideally of course every widget should also be available as a short code and this plugin would then be uneccessary.
November 20th, 2009 at 1:01 am
Hi Adrian,
Yes I can see two year old pirates could be quite distracting – I have the ambitious young chef problem, but I think that is easier to deal with!
I think that there is a problem for the plugin with
Because the plugin is registering the “shortcode” sidebar, and plugins run before themes I think – it seems to grab the no. 1 slot. This seems to shift any theme numbered sidebar to 2nd place – this happens with the default theme. This is not a problem with themes that register and access their sidebars by name (eg: the ithemes series).
I did play around seeing if I could get the “shortcode” sidebar to register later, but no go.
Because of this I did spend some time looking at whether one could use the dummy “inactive widgets sidebar” and did hit some annoyances there and have not had a chance to get back to it.
This is sort of related to the Sidebars and Switching themes problem if one want to reuse a group of widgets – see http://wordpress.org/extend/ideas/topic.php?id=2550.
So to fix for you…. you could
November 20th, 2009 at 7:43 am
Thanks for the response Anne-Marie and yes, I agree it is undoubtedly an inherent problem with the theme and not the plugin, (or maybe not a problem, but perhaps a fundamental issue with sidebar management in WP, as it says also in the link you provided)
I did actually get the theme to work with the plugin by tweaking functions.php, but then, as we always do, went off at another tangent and ended up working on something else.
I’m quite enjoying learning about how WP fits together and looking at how plugins and themes are coded is a great help.
Thanks again and have a nice day
January 11th, 2010 at 1:07 am
While I liked the feature that this plug-in gave at first, I have noticed in the second day using it that it doesn’t seem to play well with some other plug-ins. It sometimes switches the order of all of my widgets (on other pages and sidebars) around, and sometimes deletes the content within my other sidebars completely. I’m not sure if it’s just a specific plug-in that I have that it doesn’t work well with as I use several, but those who are planning to use this in conjunction with some of the more common plug-ins may want to beware. Back up the content & code within your sidebar widgets so that if it gets deleted you can at least replace it easily. I’m having to re-do a lot of things on our new site because I hadn’t anticipated this issue, but I at least wanted others to be aware.
If there is any fix I’d be interested to know what it is, because otherwise I’m left with creating the new page template, sidebar etc.
January 11th, 2010 at 3:55 am
Dear IKS,
If you look back at the comments a couple before yours, eg: Adrians http://webdesign.anmari.com/shortcode-any-widget/#comment-3955
you will see that the problem occurs with themes that use numbered sidebars rather than named sidebars.
No information is deleted and the effect is NOT intentional. If you deactivate the plugin your theme should grab the no.1 spot again.
Some fix ideas are mentioned above. I had spend quite a bit if time looking at it, to try to get wordpress to add the shortcode sidebar later after the themes, however did not succeed and had to move on to real work. (I’ve never liked the way that wordpress does the sidebars and this is one of the reasons why – but perhaps the problem is the themes being a bit “casual” with their sidebars? or wordpress allowing a casualness?)
A nice big warning has now been added to the plugin home page.
January 11th, 2010 at 4:27 am
Hi Anmari,
Unfortunately, even when I deactivated the plug-in nearly all of my content from the widgets in my other sidebars was gone (save for two widgets, I think). It’s rather unfortunate that the problem seems to be the theme, as I don’t intend to change it and I’m not sure how to go forward with the fix that involves editing functions.php and sidebar.php (I really wouldn’t know what to change). Oh well, the solution would have been perfect if it had worked.
February 7th, 2010 at 6:29 pm
I have a widget that is a daily quote, can I use this plug-in to post the quotes on a post page instead of the side bar and it include the previous quotes on the same page?
March 2nd, 2010 at 4:58 pm
Love the plugin, i have been using it in conjunction with tables to put 3 widgets in a row. it’s a shame that it does not put the widget block/header graphic in. Is it possible to do this?
March 2nd, 2010 at 10:57 pm
Hi Jon,
Why don’t you just put the html of the widget header in around the shortcode? That should be pretty simple.
March 4th, 2010 at 10:29 pm
Hi Anna – Thanks for that simple solution, unfortunately i’m a simple person and don’t know how to do any of that. Please can you show me?
March 6th, 2010 at 4:21 pm
[...] Fuzz Is this possible? I would like to place the widget without using a sidebar Have a look at this [...]
April 3rd, 2010 at 6:43 am
thank you very much… three months searching for this… very powerful plugin.
April 12th, 2010 at 1:51 am
I just found this plugin, great idea by the way. It works fine if I have just one of a given item, for example, “Tabber Widget”, but when I add the second, and I set each to id=”tabber-widget-1″, and id=”tabber-widget-2″, neither one shows. Did I misunderstand?
April 12th, 2010 at 4:16 am
Hi Danny, it does work with multiple instances of many widgets – I don’t know the tabber widget.
The trick is to be sure that you have the correct id’s, and the id names correct. For example, to double check I added two tag cloud widgets to my play system. The id’s ended up being “tag_cloud-3″ and “tag_cloud-4″. You also need a separate do_widget for each – don’t put in the same shortcode
Note:
Hover over the widgets or the edit link in the widget sidebar to really see what the id’s are. See also
http://webdesign.anmari.com/the-shortcode-any-widget-handles-multiple-instances/
April 13th, 2010 at 6:30 pm
I did notice latter the underscore, vs hyphen, however I am still having problems. I looked in the shortcodes sidebar, I assume that is the one you are talking about, and tried to hover over in both safari, and in firefox, and I did not see the widget id, I am running 2.9.2 I haven’t moved over to the beta yet. The widget in questions is a free one from iThemes.com, it uses jQuery to give multiple tabs each creating it’s own widget for content. It is the tabber itself that I put into the shortcodes sidebar, not one of the children. Thanks for your help!
Danny
April 16th, 2010 at 7:16 am
Hello!
I have made translation of Your plugin into Belorussian. Please check Your email & answer to me.
April 16th, 2010 at 8:04 am
Danny, I fired up safari myself and yes I see that it is rather unhelpful in this case. Unless Safari has some sort of web developer tool that will let you “inspect the element”, you will have to run firefox or even chrome – the correct id’s are the only way to uniquely identify a single instance if you are going to have multiple instances. If you do NOT need to have multiple instances of the same widget, then it is much easier to just use the name.
Note: Using the name will cause all of them to be listed too – if you get the order right, this may achieve whatever effect you are trying to achieve, without having to identify them individually.
April 19th, 2010 at 11:27 am
@anna-marie, why you ignore my comment & my transalation, what i sent to you?
April 20th, 2010 at 3:49 am
Marcis,
I did not receive an email with translation for this plugin – I did receive multiple emails for the breadcrumb widget translation. That translation has been included in the latest update, with acknowledgement in the changelog.
Thank You
April 26th, 2010 at 2:11 pm
Hi Anna-Marie,
want to use your plugin on my site the same way you did (in combination with query posts) because I tink it’s a very simple solution.
The Problem is: Nothing shows up in my page after using the shortcode. But I think I did everything exactly like you did.
- Getting the Plugins
- Drag Query-Posts into Shortcodes Sidebar
- Using [do_widget "Query Posts"] somewhere in my page
I’m using WP 2.8.4. I also tried the Plugin in another Blog with just the same result: nothing is showing up in my page. By the way the query-posts widget is working well when I put it into another sidebar.
Any Ideas?! I really want to use this, because I do not have to change the Code this way…
THX for your help!
April 27th, 2010 at 3:31 am
Hi liebesbeweise,
I have just doubled checked it myself on wp3.0beta and no problem.
Procedure:
drag query posts widget to a visible sidebar and configure it.
check that the output is what you want.
Now drag that self same widget from the visible sidebar to the shortcodes sidebar.
Create a page or post with [do_widget "Query Posts"], and publish it, View it.
If that still does not work, Try a different widget (maybe a plain text one) to see whether with the do_widget, this should at least tell us whether it is only QP’s that are a problem on your system.
June 29th, 2010 at 10:52 pm
Hi & thanks for the plugin Anna-Marie
Using the ID attribute gives weird results, especially when you move the widgets around in the sidebar.
If you’re interested, I modified a little your code to use widget instance IDs instead of widget names:
http://pastebin.com/tM5K4jyL
The unique ID is shown in the widget options after you press save.
(ps: I’m using this for a theme I’m developing – http://wp.digitalnature.eu/atom/widgets
June 30th, 2010 at 12:57 am
Hi Mile,
Thanks for letting me know.
Perhaps you could clarify what you mean by weird results? (If it is style changes as you move a widget from one sidebar to another, that could be because the theme’s css uses the sidebar in the selectors?). the instance id should stay the same so I cannot think what else might happen as you move it? I think keeping the html id was intended to cope with those circumstances where special styling had been developed possibly using the id’s, so that that styling would carry through to the widget in the page.
Note that the name is good to keep because
some inexperienced folk are using wordpress these days and they don’t know how to find the id, whereas name is quite visible
some browsers (was it safari?) the id was not easily visible on hover, one had to go to page source to find it – a pain
Also FYI and for other readers, cambridge newmedia (the ym plugins) also have a shortcode widget plugin.
June 30th, 2010 at 12:35 pm
well for example using [do_widget Calendar id=2] will output both Calendar widgets, instead of just the 2nd.
anyways, here’s my final take (I added the ‘number’ parameter as well):
http://pastebin.com/zLV2q7Bg
here you can see what I meant by IDs (basically a unique md5 hashed string from the widget instance ID)…
another idea is to remove the widget title html from $output using php DOM functions, instead of hiding it…
June 30th, 2010 at 12:46 pm
Hi Mile,
that’s probably because your syntax is not quite right – you are doing two things in one. So either do one or another:
[do_widget calendar] will do all calendars in the shortcode sidebar
[do_widget id="calendar-2" ] will do only one instance
This post has related info http://webdesign.anmari.com/the-shortcode-any-widget-handles-multiple-instances/
June 30th, 2010 at 1:12 pm
ah I see now.
still, the ID you use is hard to figure out by the common WP user. Aren’t the generated IDs from the widget options, or the Widget Name + Number (in the sidebar) better solutions?
you should really modify your code to support that, because this plugin has a lot of potential
Bye
July 1st, 2010 at 3:20 am
Hi Mile, I think 3.0 must have changed something because when I wrote the plugin that is exactly what it was using. However looking now it seems that the widgets have longer id’s now. Now I see
widget-22_archives-2 instead of archives-2.
I do like to keep them up to date but time is an issue!
Thanks for flagging it though – I’ll make a note to look at it when I can.
July 13th, 2010 at 8:32 am
hi anne-marie and thank for sharing your pretty plugin.
i would like to call it from the theme instead of shortcode, how would be the proper sintax to call it?
in guess something like
if ( function_exists(‘do_widget’) )
{do_widget(‘SimpleLogin’);
but this way isn’t work to me.
could you explain it to me?
best regard, pescadito
July 13th, 2010 at 11:59 am
Hi pescadito,
I have not tried this myself but something like
do_widget(array(
‘sidebar’ => ‘Shortcodes’,
‘id’ => ‘id of widget you want’, or 0=> widgetname
‘title’ => ‘true’ ))
However I don’t recommend this, since it presupposes that the widget configuration has already been done in the shortcode sidebar and somehow it seems wrong to me that a theme should require config to be already in place? Themes are usually somewhat self contained and standalone.
July 13th, 2010 at 1:08 pm
ok anne-marie,
you have rigth, your point it’s true.
perhaps it can be done more properly with something like
but some widgets have a lot of options and setting this in the widget sidebar is more confortable, at last while we are setting up the blog.
and thank for your time,
best regard, pescadito.
November 18th, 2010 at 4:04 pm
Hi Anna-Marie,
I’ve been goggling around looking for a simple yet powerful plugin that allow me to add widgets in page or post. I’ve been using widget logic before.
I’ve tried the plugin and it work like a charm in a page. However it didn’t work and nothing shows when i included the same widgets and shortcode in a post. I’ve make sure to turn off the widget logic but still no avail.
Btw, the theme i’m using is lifestyle 4.0
Please help me.
Eddy
November 22nd, 2010 at 2:48 pm
Hi Eddy,
I do not know what you mean by switching the widget logic off. The plugin is quite simple and it fit works in a page, then it should work in a post unless some other plugin is blocking filters, or you have not identified the widget suitably for the plugin. See below.
When viewing your post, add to the url (replace ? with & if you already have a ?)
?do_widget_debug
If the do_widget shortcode fires, then it will list your sidebars and the widget ids and a bunch of other statements.
Find the shortcode sidebar and see what the id of the widget is. See any message below about not finding widgets or names.
Check that you have either
Using the shortcode-any-widget plugin, please note that you can use either:
[do_widget id=tag_cloud-3]or
[do_widget "Tag Cloud"]note the quotes, and of course replace tag cloud with your widget name.
See here http://webdesign.anmari.com/category/plugins/shortcode-any-widget/