最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add shortcode to html widget

programmeradmin2浏览0评论

I'm trying to include a shortcode to an html widget by adding below code to functions.php

add_filter( 'widget_text', 'shortcode_unautop'); 
add_filter( 'widget_text', 'do_shortcode');

and to the html widget <script>alert("'" + [user_email] + "'");</script>

but it keeps saying user_email is not defined.

I'm trying to include a shortcode to an html widget by adding below code to functions.php

add_filter( 'widget_text', 'shortcode_unautop'); 
add_filter( 'widget_text', 'do_shortcode');

and to the html widget <script>alert("'" + [user_email] + "'");</script>

but it keeps saying user_email is not defined.

Share Improve this question edited Dec 2, 2019 at 15:32 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Dec 2, 2019 at 12:46 Andre SAndre S 1 3
  • edit your question to show us the exact HTML code you use in the widget. – Kaperto Commented Dec 2, 2019 at 12:54
  • If the filter didn't work, it would just print the text. But apparently it does work, because you get an error message.The problem seems to be that the shortcode is ill defined. – cjbj Commented Dec 2, 2019 at 15:32
  • yes it was. thank you. – Andre S Commented Dec 3, 2019 at 6:51
Add a comment  | 

1 Answer 1

Reset to default 1

First thing you need to do is drag & drop a Text widget to your WordPress sidebar on the Appearance » Widgets screen in your dashboard. After adding the widget, you can simply add your shortcode inside the text edit area of the widget.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论