admin管理员组

文章数量:1406064

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.

本文标签: Shortcode in Text Widget not working