0
votes

i've written a plugin which shortcodes can easily be used in every post and page. As this plugin can be useful in a sidebar as well i want to make the text widget usable for my shortcodes.

When i googled this i found out that i can use the add_filter() function to ensure that, but this is only possible if i have access to the theme's functions.php. But as i am the creator of the plugin and not of the theme, this is not usable for me.

Does anybody know how i can make a shortcode which is introduced with a plugin usable in the widgets section?

Thanks!

2
Why don;t you create widgets as same functionality as shortcode ??? it also simple...Find Docs from here http://codex.wordpress.org/Widgets_API.. - Akshay Paghdar
Thanks. But what exactly do you mean. I then have to create a class first - like this: class Foo_Widget extends WP_Widget { right? - Torben
Yes...You need to create class for widget... But you can try with add_filter('widget_text', 'do_shortcode'); in your plugin's main file... I haven't tested this is plugins. - Akshay Paghdar
But may be it will work from your plugin...I hope it'll work... - Akshay Paghdar

2 Answers

1
votes

Open your theme's function file.

Find a free spot after the opening php tag that isn't part of a function.

add this:

if (!is_admin())

{
   add_filter('widget_text', 'do_shortcode', 11);
}

save the file and you should be all set.

-1
votes
  1. Open your page in edit mode.
  2. Select your page location and line where you want to add short code.
  3. Add code here and update..