Remove p tags inside text widgets in WordPress 4.8

Plugins , Tips , Widgets ,

How to remove p tags inside text widgets in WordPress 4.8 ?

If you’ve already updated your website to WordPress 4.8, then you may be surprised to learn that the Classic Text Widget has been replace with a Text Widget that now uses Visual Editor, the same editor used for editing posts and pages. This is indeed improvement, and your content can now be displayed as rich text. Unfortunately it is also a step backward for most of you who are using HTML code or shortcodes since all markup will be stripped, and there is no check box to disable paragraphs, so wpautop function will be executed and additional paragraphs will be present in your markup even when code is updated trough text editing mode. If you never edit the code in your text widget, you’ll be okay. There is ongoing discussion with WordPress core development team regarding issues with new text widget. So, how to remove p tags inside text widgets in WordPress 4.8?



Of course, like with many other things and problems encounter with WordPress there are also solutions for this.


1.Removing wpautop function

Simply add following line of code inside theme folder / functions.php file to remove wpautop function from text widgets:
remove_filter('widget_text_content', 'wpautop');

If you want to have permanent fix, you should add code from child-theme functions.php file or alternatively you can use some plugin which allows adding functions and php code, like My Custom Functions plugin. In this way, you will still have new text widget and all its functionality but it won’t wrap your code with unnecessary paragraphs.


2. Use plugin for adding Classic Text Widget

You can also have Classic WordPress Text Widget back since it is available as a plugin.



Some of you may think that someone in the WordPress core team seriously messed up with this new Visual Editor inside text widget, but they planned this for quite a while, and there are many users who actually wanted to to use rich text editor in their text widgets without needing to install additional plugins or to be forced to learn HTML. This is after all improvement, and all users need to have same functionality and to maintain formatting when switching between themes. But, if you’re a heavy text widget user, and especially if you are using commercial themes from Theme Forest with a lot of custom widget areas you’ll defiantly need one of provided solutions.

Leave a Comment

Your email adress will not be published. All fields are required

HTML is not allowed