[英]Prevent TinyMCE wrapping text in p tags on Wordpress
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.
这个问题看起来像以前在 Stack Overflow 上提出的问题的重复,但这里找到的解决方案都没有对我有用。
TinyMCE wraps anything you put in there inside p tags. TinyMCE 将您放入其中的任何内容包装在 p 标签中。 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.
我需要更改 tinymce 的强制根块设置来防止这种情况,但我不知道如何在 Wordpress 上实现这一点。
I tried putting the code found here in my functions.php, but It did not work.我尝试将此处找到的代码放在我的函数中。php,但它不起作用。 Also, the problem doesn't revolve around "wpautop".
此外,问题并不围绕“wpautop”。 It's just a TinyMCE problem: it puts the p tags as a default behaviour because it needs a root block.
这只是一个 TinyMCE 问题:它将 p 标签作为默认行为,因为它需要一个根块。 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.
添加的 p 标签只是破坏了我的布局,放置了不必要的 html 元素。
I tried using the TinyMCE advaced plugin, which has this option:我尝试使用 TinyMCE 高级插件,它有这个选项:
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.但是,如果未选中此项,则会“剥离”所有 p 标签,即使是我有意在编辑器中使用的标签。
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 .我想要实现的只是防止编辑器添加不需要的 p 标签,同时保留我故意使用的 p 标签。
Is there a way to edit the forced_root_block setting of TinyMCE on Wordpress?有没有办法在 Wordpress 上编辑 TinyMCE 的强制根块设置?
EDIT: After too many hours I was messing up between two different Wordpress installations I was working on at the same time. 编辑:经过太多时间我在同时处理的两个不同的Wordpress安装之间搞乱了。 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. 在我的functions.php中,TinyMCE停止在p标签内放置任何内容。 The
Stop removing the <p> and <br /> tags when saving and show them in the Text editor
of TinyMCE Advaced needs to be checked. Stop removing the <p> and <br /> tags when saving and show them in the Text editor
TinyMCE Advaced Stop removing the <p> and <br /> tags when saving and show them in the Text editor
中Stop removing the <p> and <br /> tags when saving and show them in the Text editor
需要进行检查。
You could try to set 你可以尝试设置
forced_root_blocks: false,
You can have a look at this wordpress plugin to change this setting. 你可以看一下这个wordpress插件来改变这个设置。 Here is another possibility: http://wpengineer.com/1963/customize-wordpress-wysiwyg-editor/
这是另一种可能性: http : //wpengineer.com/1963/customize-wordpress-wysiwyg-editor/
function my_mce_options($init){
$init['wpautop'] = false;
$init['indent'] = true;
$init['tadv_noautop'] = true;
return $init;
}
add_filter('tiny_mce_before_init','my_mce_options');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.