1

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.

  • It looks good to me. Did you check the HTML source code or try this on the default theme? – birgire Jul 29 '14 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 Jul 29 '14 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 Jul 29 '14 at 20:16
  • good to hear you worked it out. – birgire Jul 29 '14 at 20:26
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.

  • That's exactly what it was. Go figger! – Lorne Jul 30 '14 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.