How to remove paragraph tags from Advanced Custom Fields outputs

Wordpress logo over top a screen displaying code

If you’re using the Advanced Custom Fields plugin, you may have found yourself frustrated by WordPress’ forcing of wrapping non-formatted text on pages with paragraph tags when that’s not what you want. Here’s the fix.

When adding a new field, you’ll see a setting called Formatting. Selecting No Formatting from the dropdown turns that field into essentially raw HTML. When you’ve done this but when you add a value into the field when writing your post and you’re still seeing it wrapped in a paragraph tag, it’s because WordPress is built to do just that by default.

Advanced Custom Fields formatting option screenshot

The way around this is to add a function that ignores the wpautop filter set in the core.

Open your theme’s functions.php file and add the following code:

function the_field_without_filters( $the_field=null ) {
    remove_filter('acf_the_content', 'wpautop');
    if( $the_field ) {
      the_field( $the_field );
    } else {
    add_filter('acf_the_content', 'wpautop');

Save and you’re good to go.

Share this:
My big, fat head


I'm a front end developer and designer specializing in WordPress, User Experience, SEO, and have been working with businesses of all sizes since 1999 in helping build web properties that gets the job done.

Subscribe! You know you wanna!

Get new articles from my blog sent directly to you via email. You know the drill, send me your details and you're in.