How to Remove p and br Tags from Contact Form 7?
Contact Form 7 (CF7) is one of the most popular free form plugins for WordPress. With CF7, it’s easy to create any form you want.
Although it’s an excellent extension, there’s always an annoying behavior. By default, it wraps our lines in <p> tags as in the case of general messages.
Unlike in this post, this is often not so useful because we often want a custom layout for our forms that is driven by paragraph component overflow.
Here’s a way to remove all <p> and <br /> additions from your forms!
CF7 is a great tool but sometimes it adds a little extra HTML that you might want to get rid of in your pages and posts.
Short Code and It’s Solved
We’ve created a quick code snippet that you can use to remove <p> and <br /> from Contact Form 7.
Luckily, it’s easy to turn off, add the following line to your wp-config.php file:
// Remove auto p and br from Contact Form 7 define( 'WPCF7_AUTOP', false );
Another option is to use a filter in your theme (functions.php) or in your plugin:
// Remove auto p and br from Contact Form 7
add_filter('wpcf7_autop_or_not', '__return_false');
The last code snippet does the same thing but attaches the code to the theme and not to your WordPress instance.