WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have my own widget, that uses WP_Widget class, and executes its code inside function in this class. Is there any ways to run this widget using shortcode inside post?

This is how my widget structure looks like:

add_action( 'widgets_init', 'register_my_widget' );
function register_my_widget() {}
class My_Widget extends WP_Widget () {
    function My_Widget() {}
    function widget() {}
    function update() {}
    function form() {}

How can I add the shortcode for executing this widget?

share|improve this question
up vote 0 down vote accepted

I think you are out of luck as wordpress core doesn't have this kind of functionality. Quick googling shows that there are plugins to do that like this one http://wordpress.org/extend/plugins/amr-shortcode-any-widget/, but if you have programming skills you should probably write a shortcode handler with/instead of the widget.

share|improve this answer
Thanks for the answer. I already found this digwp.com/2010/04/call-widget-with-shortcode method, but it's inappropriate for me, because there is manipulation with core files. Also I found wordpress.org/extend/plugins/gtrans this plugin, which can be called with both shortcode and widget methods. I think, it's possible to do this with help of another function in the widget class like this: widget(){calling to sc_handler()}; shortcode_handler(){my code}. – drake2300 Nov 29 '12 at 12:40
yes, you should have the main do_stuff($args) function somewhere in your plugin, and let it handle all the generation of the output based on the parameters, then just call it from your widget code and shortcode code. Just keep it a simple function and not part of the widget class so it will be easier to call it from the shortcode. – Mark Kaplun Nov 30 '12 at 5:50
finally I did it. thanks for helping me. – drake2300 Nov 30 '12 at 10:19

Your Answer


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.