4
votes

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

I've been trying to solve this problem for hours with no luck so far. The question looks like a duplicate of questions asked previously here on Stack Overflow, but none of the solutions found here worked for me.

TinyMCE wraps anything you put in there inside p tags. I need to change the forced_root_block setting of tinymce to prevent this but I have no idea on how to achieve that on Wordpress.

I tried putting the code found here in my functions.php, but It did not work. Also, the problem doesn't revolve around "wpautop". It's just a TinyMCE problem: it puts the p tags as a default behaviour because it needs a root block. In my case I don't need a root block, because the editor's content is just a plain text whose root block is in my template's code. The added p tags simply break my layout, putting unnecessary html elements.

I tried using the TinyMCE advaced plugin, which has this option:

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

but when this is not checked has the effect of "stripping" all the p tags, even the ones I intentionally use in the editor.

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

Is there a way to edit the forced_root_block setting of TinyMCE on Wordpress?

2
You mean that when you press enter in the visual mode, it should add two <br /> instead of a new paragraph?vard
No, if I typed "Lorem Ipsum" in the editor, it automatically wrapped it in p tags. And that's what I wanted to prevent. Found the solution, edited my post. Thank youmickmickmick
You better should post the solution as an answer and accept it (after 24h), so your question will be marked as resolved.vard

2 Answers

6
votes

EDIT: After too many hours I was messing up between two different Wordpress installations I was working on at the same time. The solution of the linked post worked for me, but I was checking the results on the other site. By 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. The Stop removing the <p> and <br /> tags when saving and show them in the Text editor of TinyMCE Advaced needs to be checked.

0
votes

You could try to set

forced_root_blocks: false,

You can have a look at this wordpress plugin to change this setting. Here is another possibility: http://wpengineer.com/1963/customize-wordpress-wysiwyg-editor/