Home Forums General Issues Removing Paragraph Tags from WYSIWYG Fields?


Removing Paragraph Tags from WYSIWYG Fields?

  • This is supposedly solved but I’m still having a problem. This does not work:
    remove_filter ('acf_the_content', 'wpautop');

    First, my WYSIWYG fields are in a repeater, if that makes a difference.

    Second, my fields contain shortcodes. If I output my fields like this:
    the_sub_field('wysiwyg_field', false, false);
    The extra line breaks and p tags are gone, but shortcodes are not executed.

    update: guy_b’s solution did solve the issue.

  • guy_b solution:

    //Remove WPAUTOP from ACF TinyMCE Editor
    function acf_wysiwyg_remove_wpautop() {
        remove_filter('acf_the_content', 'wpautop' );
    add_action('acf/init', 'acf_wysiwyg_remove_wpautop');<code></code>

    worked for me
    both on field and subfield


    • o2Xav

    • March 14, 2019 at 8:46 am

    For those who would like to strip p tags, but keep br tags (or other tags), you can process the output of the field with strip_tags like so :

     $field = get_field('my_wysiwyg_field');
    $formatted_field = strip_tags($field, '<br>');
    echo $formatted_field; ?>

    Simple, yet effective

  • Hi I can’t get this to work. I am using this code in my functions.php:

    function my_acf_add_local_field_groups() {
      remove_filter('acf_the_content', 'wpautop' );
    add_action('acf/init', 'my_acf_add_local_field_groups');

    I am using wordpress 5.1.1 and using ACF PRO 5.7.13. I am using WYSIWYG fields inside a flexible content field. So I am using <?php the_sub_field('name_subfield'); ?> in my .php file

    Does anyone know if this is due to an update or if this never worked?

    • guy_b

    • March 21, 2019 at 10:20 am

    @rrmeines it shouldn’t (in theory) make a difference how the wysiwyg field is being inserted since the ‘acf/init’ hook fires after ACF is loaded, so wpautop should be removed for any fields that use it.

    Maybe there is something else that is using the native ‘the_content’ filter which is overriding the acf filter?

    I’ve never tried using wysiwyg in a repeater or flexible context though, so that might be related to the problem you’re having.

    • webprom

    • December 11, 2019 at 6:27 am

    @o2xav I love you ! 🙂

Viewing 6 posts - 26 through 31 (of 31 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.