首页 文章

删除tinyMCE中的额外p标记

提问于
浏览
14

当您从word文档复制并粘贴到tinyMCE编辑器时,有时会出现不需要的 <p> 标记:

<p>&nbsp;</p>
<div class="starpasspro-example-question">
   <p><strong>Example: Levels of strategy</strong></p>
   <p>Microsoft is one of the world&rsquo;s largest organisations, providing corporate solutions to businesses throughout the world to help them realise their fullest potential. At Microsoft, there are three levels of strategy as follows:</p>
</div>
<p>&nbsp;</p>

这里生成的代码我想以任何方式删除 <p> 标签吗?

4 回答

  • 0

    tinymce.init({ }); 中添加这些行

    Example:

    tinymce.init({
        forced_root_block : "", 
        force_br_newlines : true,
        force_p_newlines : false,
    });
    
  • 3

    它会有所帮助 .

    添加到 tinymce.yml 文件中

    forced_root_block : "" 
    
    force_br_newlines : true
    
    force_p_newlines : false
    
  • 15

    是的,这是可能的 . 有一种安全的方法可以删除您要删除的所有html元素(您可以定义要保留的内容) . 它是通过使用tinymce配置参数 paste_preprocess 和自定义函数 strip_tags . 看看here .

  • 0

    将此添加到functions.php文件中,将通过向tiny_mce_before_init挂钩添加一些参数来删除标准p-tags标记 . 如果您想了解它的工作原理,可以在此页面进一步阅读:https://codex.wordpress.org/TinyMCE

    ////////////////////////////////////////////////////////////////////////
    //////////REMOVE STANDARD <P> FROM TINYMCE EDITOR/////////////////////////
    ///////////////////////////////////////////////////////////////////////
    function my_format_TinyMCE( $in ) {
    $in['forced_root_block'] = "";
    $in['force_br_newlines'] = TRUE;
    $in['force_p_newlines'] = FALSE;
    return $in;
    }
    add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );
    

相关问题