Wordpress - How to make plugin's short code usable in text widget

一个人想着一个人 提交于 2021-01-29 07:06:46

问题


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!


回答1:


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.




回答2:


  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..


来源:https://stackoverflow.com/questions/21610569/wordpress-how-to-make-plugins-short-code-usable-in-text-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!