admin管理员组文章数量:1122846
I created a plugin and tried to use its shortcode in a Custom HTML Widget, but for some reason it's outputting [my_shortcode_name]
instead of executing the shortcode.
The shortcode works fine if I place it on the page or in a Text Widget.
How can I make it work in a Custom HTML Widget?
I created a plugin and tried to use its shortcode in a Custom HTML Widget, but for some reason it's outputting [my_shortcode_name]
instead of executing the shortcode.
The shortcode works fine if I place it on the page or in a Text Widget.
How can I make it work in a Custom HTML Widget?
Share Improve this question asked Apr 28, 2019 at 8:39 Pikamander2Pikamander2 6086 silver badges20 bronze badges2 Answers
Reset to default 11I was able to make it work by adding these two lines to my theme's functions.php
file:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
The Custom HTML Widget now correctly executes the shortcode function and outputs the result.
For the Custom HTML Widget it's better to use this hook:
add_filter( 'widget_custom_html_content', 'do_shortcode' );
本文标签: pluginsHow can I make my custom shortcode work in a Custom HTML Widget
版权声明:本文标题:plugins - How can I make my custom shortcode work in a Custom HTML Widget? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307633a1933381.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论