The new rich text widget that came with the 4.8 update seems to add a filter to widget's content before outputting the data (probably the_content).

I just noticed that if i use a shortcode in the new text widget, it will mess the entire thing ( for example, it will replace the X letter with &#215; which is the HTML entity equivalent for × mark, add random <p>, etc.). The filter is added to the wp_options table under widget_text, like this:


Now if i replace the 5th and 6th values with this:

    s:1:" ";
    s:1:" ";

The filter is applied no more. If you already have a text widget added before updating to 4.8, there won't be a problem. But the moment you click Save on the widget after you update to 4.8, the problem appears.

I don't want to disable the filter entirely, since there might be other text widgets on the page.

Is it possible to detect the shortcodes and turn off the filter for them?

1 Answer 1


We now have a new filter widget_text_content introduced in 4.8 src, with the following default callbacks:

add_filter( 'widget_text_content', 'capital_P_dangit', 11 );
add_filter( 'widget_text_content', 'wptexturize'          );
add_filter( 'widget_text_content', 'convert_smilies',  20 );
add_filter( 'widget_text_content', 'wpautop'              );

that are applied if the filter settings, for the widget instance, is set to 'content'.

When you remove the filter settings by hand from the wp_options table, it seems to be reset during the update method src.

See trac ticket #35243 for more info.

  • Hi! Thanks. So, is there a chance to turn off these filters just for my shortcodes? Or do i have to turn them off for everything? That won't be nice...
    – Johansson
    Jun 13, 2017 at 9:24
  • Yes that would be possible, with a hack, using e.g. the widget_display_callback to check if the text widget contains any shortcode and remove those above filters, else leave them on for others. But this widget seems to be a work in process these days, so we should stay tuned ;-)
    – birgire
    Jun 13, 2017 at 10:25
  • As always, nice to read your detailed answer. My theme just got rejected again because it doesn't display shortcodes properly inside the widget, so i guess i have to create a widget for each of them :( Automattic please!
    – Johansson
    Jun 13, 2017 at 10:37
  • 1
    Sorry to hear that, it's a long process, that will hopefully be rewarding for you in the end. Custom widgets are probably a good workaround.
    – birgire
    Jun 13, 2017 at 10:46

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.