Wordpress - 如何使插件的短代码在文本小部件中可用 [英] Wordpress - How to make plugin's short code usable in text widget

查看:49
本文介绍了Wordpress - 如何使插件的短代码在文本小部件中可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个插件,可以在每个帖子和页面中轻松使用短代码.由于这个插件在侧边栏中也很有用,我想让文本小部件可用于我的短代码.

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.

当我用谷歌搜索这个时,我发现我可以使用 add_filter() 函数来确保这一点,但这只有在我有权访问主题的functions.php 时才有可能.但是由于我是插件的创建者而不是主题的创建者,所以这对我来说不可用.

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?

谢谢!

推荐答案

打开你的主题的函数文件.

Open your theme's function file.

在不属于函数的 php 标签之后找到一个空闲位置.

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

添加:

if (!is_admin())

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

保存文件,你应该已经设置好了.

save the file and you should be all set.

这篇关于Wordpress - 如何使插件的短代码在文本小部件中可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆