0
votes

I am using ACF, and using TinyMCE Advanced plugin.

When editing posts, the editor inserts new links into p tags, which I am trying to prevent as I am using the code tag and if there is a return within the code within the code tag, it wraps it in a new p and code block that then breaks the layout of the post.

I have tried playing with the plugin settings to check to remove the p tags, however no luck.

I have searched and found that I should be setting forced root block to false, however I am still unable to get it to work:

add_filter('tiny_mce_before_init', function ($init) {

        //Prevent <p> tags in editor
        $init['forced_root_block'] = false;
        $init['force_br_newlines'] = false;
        $init['force_p_newlines'] = false;
        $init['convert_newlines_to_brs'] = false;

        return $init;
    });

When viewing the post in Text tab, the code shows no P tags, however when editing within the visual tab, its breaking it all out into p tags.

Any ideas on how to resolve?

1

1 Answers

0
votes

When you output the content, while in a loop, you can sanitize the output to remove any and all tags using wp_strip_all_tags.

Properly strip all HTML tags including script and style.

<?php wp_strip_all_tags( the_content(), true ); ?>

(true or false for line breaks). Same thing for ACF, just englobe the output in it.

Alternatively, you can remove any auto <p> tag applied as line break by removing the wpautop via remove_filter in your function.php file.

<?php remove_filter( 'the_content', 'wpautop' ); ?>

And with an ACF editor WYSIWYG/TinyMCE

<?php remove_filter ( 'acf_the_content', 'wpautop' ); ?>