首页 文章

防止TinyMCE在Wordpress上的p标签中包装文本

提问于
浏览
4

对不起我的英语,我不是母语人士 .

到目前为止,我一直试图解决这个问题几个小时没有运气 . 这个问题看起来像是之前在Stack Overflow上提出的问题的重复,但这里找到的解决方案都不适用于我 .

TinyMCE包装你在p标签内放置的任何东西 . 我需要更改tinymce的forced_root_block设置以防止这种情况,但我不知道如何在Wordpress上实现这一点 .

我尝试将代码here放在我的functions.php中,但它没有用 . 此外,问题不仅仅是一个TinyMCE问题:它将p标记作为默认行为,因为它需要一个根块 . 在我的情况下,我没有't need a root block, because the editor'的内容只是一个纯文本,其根块在我的模板的代码中 . 添加的p标签只会破坏我的布局,放置不必要的html元素 .

我尝试使用TinyMCE advaced插件,它有这个选项:

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

但是当没有检查时,会产生“剥离”所有p标签的效果,甚至是我在编辑器中有意使用的标签 .

我想要实现的只是 prevent the editor from adding unwanted p tags ,同时 keep the p tags I intentionally use .

有没有办法在Wordpress上编辑TinyMCE的forced_root_block设置?

2 回答

  • 0

    你可以尝试设置

    forced_root_blocks: false,
    

    您可以查看此wordpress plugin以更改此设置 . 这是另一种可能性:http://wpengineer.com/1963/customize-wordpress-wysiwyg-editor/

  • 6

    编辑:经过太多时间我在同时处理的两个不同的Wordpress安装之间搞乱了 . 链接帖子的解决方案对我有用,但我正在检查其他网站上的结果 . 把这个:

    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');
    

    在我的functions.php中,TinyMCE停止在p标签内放置任何内容 . 需要检查TinyMCE Advaced的 Stop removing the <p> and
    tags when saving and show them in the Text editor
    .

相关问题