Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a widget by its shortcode on Wordpress posts / pages?

Is there any way we can assign a shortcode to already created widget and later use that

shortcode in our specific posts and pages to show that widget instead of trivial method of

showing widgets in sidebar ? I googled about this stuff didn't find anything relative.

Any suggestion would be welcome!

like image 558
Prince Singh Avatar asked Aug 29 '13 08:08

Prince Singh


People also ask

How do I add a widget shortcode in WordPress?

To add a shortcode using the Custom HTML widget, navigate to Appearance > Widgets and find the widget area where you want to insert the shortcode. Add a Custom HTML widget inside your chosen widget area and then add the shortcode call to it. Finish up by clicking the Save button below.

Can I use shortcodes in Widgets?

By default, shortcodes are disabled from being activated in a Custom HTML widget, but you can enable this functionality by adding code to your theme's functions.


2 Answers

Yes, You can call widget in Post/Page using shortcode. Follow this link to establish a system like that. http://digwp.com/2010/04/call-widget-with-shortcode/

like image 83
Balaji Kandasamy Avatar answered Oct 25 '22 14:10

Balaji Kandasamy


This might be relevant.

Widgets on Pages

https://wordpress.org/plugins/widgets-on-pages/

Observations and two questions:

This plugin allows insertion of 1 or "sets" of widgets via shortcode into pages, posts, (and Custom post types?) and it will also save a list of configured shortcodes~sets. VERY handy!

When comparing its features to the plugin Widgets Shortcode, that plugin does not provide a means to save "sets" of plugins, rather it seems to focus on inserting widgets individually. In fact, it inserts the shortcode for each widget in the bottom edge of each widget and it assigns different shortcodes to each instance of a widget. Also nice.

https://wordpress.org/plugins/widget-shortcode/

I like the granularity Widgets Shortcode provides with an individual shortcode for every instance of every widget. When running it and your plugin simultaneously even widgets saved in your plugin's "sets" are still assigned individual shortcodes. Those individual shortcodes allow using a specific widget out of a "set" in a different location without needing to create an additional instance of the widget as it appears would be required with your plugin.

Incidently, for anyone who wants both of these features, these two plugins play very nicely together on one of our WP 4.0 Multisite installations with 50+ sites and even on a site using the theme Make.

FYI: We also tested amr shortcode any widget, but had some issues with it and rather than troubleshoot it we moved on. To be fair, we were testing quickly on a site with over 160 plugins active. Yes, 160 plugins. I know, I know, but think about it for a minute. Any plugin that you can activate into that mix of 160 plugins and it does not break things or introduce issues, then it suggests a good probability of it being troublefree to use.... well at least until the next round of WP updates. :)

We also tested Widgetize Pages Light and its pro version Sidebar & Widget Manager and had no issues with either. However, if only seeking to insert widgets into pages and posts these plugins seem like overkill as they provide additional page layout functions that may duplicate theme functions and/or other plugin functions.

I was looking for a "widgets in pages" plugin that provides a TinyMCE button to insert the widget shortcodes.

Can anyone recommend one that has a TinyMCE button to insert the widget shortcodes in pages, posts and CPTs?

Ultimately I selected Widgets On Pages as having the best combination of features for this application. Its simple to understand, easy to use, versatile and has worked flawlessly for us, even along side Widgets Shortcode.

like image 26
Richard Duncan Avatar answered Oct 25 '22 12:10

Richard Duncan