Support

Account

Home Forums General Issues Removing Paragraph Tags from WYSIWYG Fields?

Solved

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

    Thanks!

  • 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?

  • @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.

  • Hi there. I have the same issue, but it is because I inserted the WYSIWYG Custom field inside a paragraph. Simply removing the <p> worked for me.

  • Amazon is the most popular online shopping website. Its started a lot of sale and quizzes for the customers. Amazon Quiz is the best way to get fantastic gifts every day.

  • After update it, that’s worked, thanks mate..

Viewing 9 posts - 26 through 34 (of 34 total)

The topic ‘Removing Paragraph Tags from WYSIWYG Fields?’ is closed to new replies.