On this page, http://www.sandfordparkslido.org.uk/events-5/ and others. I created a custom field, with advanced custom fields, so that the user can fill the content of the sidebar themselves without leaving the wordpress page they are working on.

The content of the sidebar is then pulled in with <?php the_field("sidebar_content"); ?>.

This works fine, however, I am getting some paragraph tags at the start and end of the code? This makes everything sit out of place ever so slightly, hence I want to get rid of them?

Question is, where are they coming from, so that I can delete them?

enter image description here

2 Answers 2


The problem is with WordPress's wpautop() filter. Here's what ACF says to do: https://support.advancedcustomfields.com/forums/topic/removing-paragraph-tags-from-wysiwyg-fields/

This is a normal WP behaviour – to turn all new lines into paragraph tags.

To remove this, you can try loading the value without any formatting. You can do this by providing a ‘false’ for the format parameter in the get_field / the_field funcions like so:

the_field('wysiwyg_field', false, false);

Hope that helps.

So just change your line to:

<?php the_field("sidebar_content", false, false); ?>

Update: I see further down in that thread they actually say you can just remove the filter with this line:

remove_filter ('acf_the_content', 'wpautop');

  • Hi, thanks, add, remove_filter ('acf_the_content', 'wpautop'); to function.php? Aug 3, 2016 at 16:12
  • 1
    Hmm, I've tried both and all suggestions, neither seem to work. Even though I agree they should. Aug 3, 2016 at 16:42
  • Maybe try adding a priority > 10? remove_filter ('acf_the_content', 'wpautop', 20); Also if you're using a dynamic sidebar, the widget might have an option for auto-formatting.
    – Megan Rose
    Aug 3, 2016 at 18:17

If you don't need any block formatting in the field use false. It will still allow spans inside:

<?php the_field("sidebar_content", false, false); ?>

If you want to allow only specific tags in template, like breaks, you may use this code:

            // remove tags except span and br
            $top_title = get_field('top_title_plus');
            $formatted_top_title = strip_tags( $top_title, '<span><br>');

            if( $formatted_top_title ) : ?>
                <h1 class="entry-title"><?php echo $formatted_top_title; ?></h1>
            endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.