Shortcode not working in Text Widget
-
I’m trying to use the text widget to display only the most recent ‘news’ and ‘blog’ posts instead of all recent posts.
I’ve added
add_filter('widget_text', 'do_shortcode');
to the functions.php through the editor and
[display-posts category="blog,news" posts_per_page="5"]
to the widget itself but it still displays the shortcode as text instead of executing it. I haven’t found any other solutions beyond adding the filter to functions.php
-
You added it to functions.php of your theme? I would confirm its in your theme functions.php and not a seperate, inactive theme or inside of a plugin file.
If you can, it’d be best to do so via FTP and not through the dashboard editor.
ok I replied too early, let me double check
Yep.
Went into wp-content > themes> current theme> functions.php and made sure the filter was there. Also added it to the functions.php files of the rest of the themes I have, just to see… still not displaying the shortcode :/
hmm, that’s interesting. I know out of the box WordPress doesn’t support short codes in widgets (which your aware of), and it should work after adding in that filter.
Maybe try adding a priority to the filter?
add_filter( 'widget_text', 'do_shortcode', 11)If that doesn’t work are you able to switch over to the default theme (2012,2013 or 2014) and trying it again with the filter in the function folder.
I would also attempt to see if its a plugin conflict by deactivating all plugins.
Evan
priority on the filter did not work, deactivating plugins did not work, and switching themes did not work.
I am completely stumped.
Wow, so am I. That’s very interesting. Right out of the box, adding that filter to your functions, things should definitely work.
After switching themes, did you re-enter the filter for the shortcode in text widgets? The functions.php is theme specific and won’t follow when you switch themes.
Yep. I added the filter to every theme’s functions.php
Weird that it’s just not working across the board…
Having the same issue. Found a bunch of posts on this but adding the filter does nothing which is bizarre.
Hey Fry, start a new thread with your specific info… they always say to do that I’m guessing because everyone’s site/setup is different and what works for one person might not work for another. Maybe there’s a new fix or workaround or someone else might know the solution!
Also, and I have no idea how, the recent posts widget just started working for my site one day… I run a twentytwelve child theme so I guess the problem worked itself out in one of the updates.
please be aware that not all code in square brackets is real shortcode –
please post in your own topic what code exactly are you trying to use, and which plugin are you using.
The topic ‘Shortcode not working in Text Widget’ is closed to new replies.