How to remove paragraph tags from Advanced Custom Fields outputs

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.

Archived under:
This site uses cookies to collect basic info to help improve your experience. Read my Privacy Policy Accept