如何在Wordpress tinymce中的双\ n \ n上转换<br/>标记?

时间:2018-11-20 18:07:57

标签: wordpress tinymce

我必须在Wordpress安装中粘贴很多内容。 +4000个帖子。问题是,原始内容很旧,并且代码中包含<br>而不是p

示例为:

This is a content and the next line is the second.<br>
This is the second line.

粘贴后,在Wordpress文本标签中,我有:

This is a content and the next line is the second.
This is the second line.

我想要这个结果:

This is a content and the next line is the second.

This is the second line.

为什么要这个结果?

由于此结果,Wordpress将在两次换行符后添加automatic p

没有这个结果,我必须在所有换行符后按ENTER来制作双行(自动p)。

我有一个清除粘贴内容的代码,该代码有效:

add_filter('tiny_mce_before_init','configure_tinymce');
function configure_tinymce($in) {
    $in['paste_preprocess'] = "function(plugin, args){
        // Strip all HTML tags except those we have whitelisted
        var whitelist = 'br,hr,p,span,b,strong,i,em,u,h3,h4,h5,h6,ul,li,ol,table,tr,td,th,tbody,thead,tfoot,blockquote,cite,abbr,a';
        var stripped = jQuery('<div>' + args.content + '</div>');
        var els = stripped.find('*').not(whitelist);
        for (var i = els.length - 1; i >= 0; i--) {
            var e = els[i];
            jQuery(e).replaceWith(e.innerHTML);
        }
        // Strip all class and id attributes
        stripped.find('*').removeAttr('id').removeAttr('class');
        // Return the clean HTML
        args.content = stripped.html();
    }";
    return $in;
}

Wordpress version: 4.9.8

感谢您的帮助!

0 个答案:

没有答案