小伙伴都知道,WordPress默认会通过wptexturize函数将纯文本字符转换成格式化的 HTML 实体,比如标签 <pre>, <code>, <kbd>, <style>, <script>和<tt>中的文本会被忽略。
这个功能对于一般写单纯码文字的人来说,程序自动将英文半角符号转换成全角符号,确实很方便。
可是如果你经常要粘贴一些代码,而且没有使用专门的代码高亮插件,你就会发现,你代码中的半角符号都会被转换成全角了!这样复制好代码却用不了,这个东东怎么解决才好呢?
这里分享的是禁止字符转义的所有代码如下,你可以根据自己的需要选择代码,添加到主题的 functions.php 文件:
// 取消转义 代码来自 Quotmarks Replacer
$qmr_work_tags = array(
'the_title', // http://codex.wordpress.org/Function_Reference/the_title
'the_content', // http://codex.wordpress.org/Function_Reference/the_content
'the_excerpt', // http://codex.wordpress.org/Function_Reference/the_excerpt
// 'list_cats', Deprecated. http://codex.wordpress.org/Function_Reference/list_cats
'single_post_title', // http://codex.wordpress.org/Function_Reference/single_post_title
'comment_author', // http://codex.wordpress.org/Function_Reference/comment_author
'comment_text', // http://codex.wordpress.org/Function_Reference/comment_text
// 'link_name', Deprecated.
// 'link_notes', Deprecated.
'link_description', // Deprecated, but still widely used.
'bloginfo', // http://codex.wordpress.org/Function_Reference/bloginfo
'wp_title', // http://codex.wordpress.org/Function_Reference/wp_title
'term_description', // http://codex.wordpress.org/Function_Reference/term_description
'category_description', // http://codex.wordpress.org/Function_Reference/category_description
'widget_title', // Used by all widgets in themes
'widget_text' // Used by all widgets in themes
);
foreach ( $qmr_work_tags as $qmr_work_tag ) {
remove_filter ($qmr_work_tag, 'wptexturize');
}
如果不用改代码,我们也可以使用专用插件:Quotmarks Replacer 插件(也可以不下载而是从后台插件市场搜索插件名字)