Shortcode in Text Widget not working

Not sure why this is not working. I get no errors, but just shows nothing at all in the text widget. The shortcode works

Not sure why this is not working. I get no errors, but just shows nothing at all in the text widget. The shortcode works on pages and posts. WordPress version 3.9.1

add_filter('widget_text', 'do_shortcode');

// Shortcode for Widget copyright Year [year]

function copyyear_shortcode() {
  $year = date('Y');
  return $year;
}
add_shortcode('year', 'copyyear_shortcode');

Any help would be greatly appreciated.

Not sure why this is not working. I get no errors, but just shows nothing at all in the text widget. The shortcode works on pages and posts. WordPress version 3.9.1

add_filter('widget_text', 'do_shortcode');

// Shortcode for Widget copyright Year [year]

function copyyear_shortcode() {
  $year = date('Y');
  return $year;
}
add_shortcode('year', 'copyyear_shortcode');

Any help would be greatly appreciated.

Share Improve this question asked Jul 29, 2014 at 19:28 LorneLorne 131 silver badge5 bronze badges 4
  • It looks good to me. Did you check the HTML source code or try this on the default theme? – birgire Commented Jul 29, 2014 at 19:54
  • I see in the source code that it renders out the php statement instead of the value. Checking in 2012 theme it works. There must be something higher up in my functions file that's causing the conflict. Will check that. – Lorne Commented Jul 29, 2014 at 20:10
  • Well, I'll be jiggered! It works after switching to 2012 theme and then back to my own theme. The widget was not updating properly, even though it appeared to be saving when I hit the button. When I switched back to my own theme I noticed the php code in the widget, which should not have been there. Replacing it with the shortcode and updating worked this time. Wierd glitch I guess. Thanks for you time :-) – Lorne Commented Jul 29, 2014 at 20:16
  • good to hear you worked it out. – birgire Commented Jul 29, 2014 at 20:26
Add a comment  | 

1 Answer 1

Reset to default 0

Try switching to a different theme (such as 2012) and back to this theme again. Some times caching plugins and some hosting environments can cause issues.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744949422a4602826.html

相关推荐

  • Shortcode in Text Widget not working

    Not sure why this is not working. I get no errors, but just shows nothing at all in the text widget. The shortcode works

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信