How To Remove Unwanted P Tags from WordPress Posts & Widgets?

Today I have added few lines of html code in HTML / Text widget of WordPress and I was constantly getting a paragraph / line space <p></p> added automatically to my widgets. It was very annoying and I had tried various plugins to disable / remove unwanted paragraph tags from my wordpress site’s widget. None of them worked for me. They might work fine for wordpress posts, but not for the widgets.

How To Remove Unwanted P Tags from WordPress Posts & Widgets?

Remove Unwanted Paragraph Tags from WordPress Widgets

So after researching for almost 30 minutes I had found a simple piece of code, that I had added to functions.php file of my wordpress theme, saved it and viola it simply removed unwanted paragraph tags / spacing from my text widget.

add_filter( 'widget_display_callback', 'wpoim_widget_display_callback', 10, 3 );
function wpoim_widget_display_callback( $instance, $widget, $args )
{ $instance['filter'] = false; return $instance; }

Remove Unwanted Paragraph Tags from WordPress Posts / Shortcodes / Pages / Content Areas

Copy / paste the following piece of code to your theme’s functions.php file and you will remove all auto generated unwanted paragraph tags <p></p> from your wordpress posts / pages and content areas.

add_filter('the_content', 'remove_empty_p', 20, 1);
function remove_empty_p($content){
 $content = force_balance_tags($content);
 return preg_replace('#

\s*+(<br\s*/*>)?\s*

#i', '', $content);
}

Or you can try out the following plugins to remove unwanted auto p tags.

Disable Automatic P Tags

Toggle wpautop

Don't Muck My Markup

Un-Line-Break

How To Fix https SSL Protocol Error on Chrome Using VPN / Proxy?
How To Earn $2250 Per Month with Whiteboard Animation Video Services?

Hasan Shahzad

Hey, I'm a Freelancer, Web & Technology Enthusiast, Digital Affiliate Marketer & Full Time Blogger for past 13 years. I love to share the Secrets / Tips for Making Money from the Internet & committed to deliver Best Online Money Making Resources at OnlineIncomeMethods.com.

Leave a Reply

Your email address will not be published. Required fields are marked *