wordpress自动过滤html标签,如何让Wordpress编辑器不过滤code标签 - 纯净天空

问题描述:

在Wordpress后台文本编辑器中,基于安全考虑,某些特殊的HTML标签如

WordPress-Visual-Editor-1024x475.png

解决方案:

个人觉得直接禁用过滤所有标签的方法不太可取,因为部分特殊标签,比如

情形一、如果使用WordPress自带的编辑器

打开控制Wordpress标签过滤的文件:

./wp-includes/kses.php

找到$allowedposttags代码位置:

$allowedposttags = array(

'address' => array(),

'a' => array(

'href' => true,

'rel' => true,

'rev' => true,

'name' => true,

'target' => true,

),

'abbr' => array(),

'acronym' => array(),

//其他代码省略...

在$allowedposttags数组中添加如下代码,表示允许标签:

'code' => array(

'class' => true,

),

保存kses.php文件,即可。

情形二、如果还安装了Kindeditor编辑器

如果还安装了Kindeditor这个富文本编辑器插件, 那么还得修改插件本身的设置才能完美避免之类的标签被过滤的问题。

网上常见的比较暴力有效的方法,首先直接找到Kindeditor影响标签过滤的文件,通常在如下位置:

./wp-content/plugins/kindeditor-for-wordpress/kindeditor_class.php

然后在函数load_kindeditor中加入filterMode: false关闭对所有标签的过滤,基于安全考虑不推荐这个方法。

function load_kindeditor(){

?>

< script type="text/javascript" >

//< ![CDATA[

var editor;

var options = {

cssPath : ['plugin_path; ?>plugins/code/prettify.css','plugin_path; ?>style.css'],

uploadJson : 'plugin_path ?>php/upload_json.php',

fileManagerJson : 'plugin_path ?>php/file_manager_json.php',

items : [

'source', '|', 'undo', 'redo', '|', 'template', 'cut', 'copy', 'paste',

'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',

'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',

'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'map', 'baidumap','fullscreen','about', '/',

'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',

'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage','flash', 'media', 'table', 'hr', 'emoticons', 'code', 'anchor', 'blockquote', 'wpmore',

'link', 'unlink'

],

afterChange : function() {

jQuery('#wp-word-count .word-count').html(this.count('text'));

},

filterMode: false //新增代码,禁用过滤标签

};

KindEditor.ready(function(K) {

editor = K.create('#content',options);

});

//]]>

< /script >

< ? php

}

更安全的方法:不过滤特定标签。找到kindeditor.js文件中的htmlTags, 在对应的结构中添加下面的代码。

code: [ 'class' ]

修改之后的代码如下(原始代码是发布版未格式化不方便阅读,这里使用工具做了格式化)

111.jpg

保存kindeditor.js文件,即可大功告成。

对于其他的富文本编辑器插件,如果也要放某些特殊的HTML标签一马,应该也有类似标签过滤的控制代码,我们只需按照类似的思路找到对应位置并做修改就行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值