Prevent TinyMCE wrapping text in p tags on Wordpress

Sorry for my English, I'm not a native speaker.

I tried to solve this problem for hours without any luck. The question looks like a duplicate of the questions asked earlier here in Stack Overflow, but none of the solutions found here helped me.

TinyMCE wraps everything you put inside p tags. I need to change the force_root_block tinymce parameter to prevent this, but I don't know how to achieve this in Wordpress.

I tried putting the found code here in my functions.php, but that didn't work. In addition, the problem does not revolve around wpautop. This is just a TinyMCE problem: it puts p tags as the default behavior because it needs a root block. In my case, I don’t need the root block, because the contents of the editor are just plain text, the root block of which is in my code template. The added p-tags just break my layout by putting unnecessary html elements.

I tried using the TinyMCE plugin that has this option:

Stop removing the <p> and <br /> tags when saving and show them in the Text editor

but if this check box is not selected, the effect of "cleansing" of all tags, even those that I intentionally use in the editor, occurs.

All I want to achieve is to prevent the editor from adding unwanted p-tags and, at the same time, support p tags that I intentionally use .

Is there a way to edit the TinyMCE forced_routine block parameter on Wordpress?

+4
source share
2 answers

EDIT: After too many hours, I worked on two different Wordpress installations that I worked on simultaneously. The linked post solution worked for me, but I checked the results on another site. Putting this:

function change_mce_options($init){
    $init["forced_root_block"] = false;
    $init["force_br_newlines"] = true;
    $init["force_p_newlines"] = false;
    $init["convert_newlines_to_brs"] = true;
    return $init;       
}
add_filter('tiny_mce_before_init','change_mce_options');

in my functions.php, TinyMCE stopped putting anything inside p-tags. Stop removing the <p> and <br /> tags when saving and show them in the Text editorTinyMCE Advaced needs to be checked.

+5
source

Source: https://habr.com/ru/post/1612448/


All Articles