禁止 WordPress 将英文半角符号转换成全角符号(字符转义)

时间:2019-08-29   阅读:477

WordPress 模式使用了 wptexturize 函数将纯文本字符转换成格式化的 HTML 实体。标签 <pre>, <code>, <kbd>, <style>, <script>和<tt>中的文本被忽略。

对于一般写单纯码文字的人来说,这个自动将英文半角符号转换成全角符号,是很方便、智能。但如果你经常要粘贴一些代码,而且没有使用专门的代码高亮插件,你会发现,你代码中的半角符号都会被转换成全角了!别人复制后,根本没办法直接使用!

那么,如何才能禁止字符转义呢?倡萌推荐大家使用 Quotmarks Replacer 插件,直接安装即可,它的所有代码如下,你也可以根据自己的需要,刷选自己要的代码,添加到主题的 functions.php 文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$qmr_work_tags = array(
  'the_title',             // 标题
  'the_content',           // 内容 *
  'the_excerpt',           // 摘要 *
  'single_post_title',     // 单篇文章标题
  'comment_author',        // 评论作者
  'comment_text',          // 评论内容 *
  'link_description',      // 友链描述(已弃用,但还很常用)
  'bloginfo',              // 博客信息
  'wp_title',              // 网站标题
  'term_description',      // 项目描述
  'category_description',  // 分类描述
  'widget_title',          // 小工具标题
  'widget_text'            // 小工具文本
  );foreach ( $qmr_work_tags as $qmr_work_tag ) {
  remove_filter ($qmr_work_tag, 'wptexturize');}

$qmr_work_tags = array( 'the_title', // 标题 'the_content', // 内容 * 'the_excerpt', // 摘要 * 'single_post_title', // 单篇文章标题 'comment_author', // 评论作者 'comment_text', // 评论内容 * 'link_description', // 友链描述(已弃用,但还很常用) 'bloginfo', // 博客信息 'wp_title', // 网站标题 'term_description', // 项目描述 'category_description', // 分类描述 'widget_title', // 小工具标题 'widget_text' // 小工具文本 ); foreach ( $qmr_work_tags as $qmr_work_tag ) { remove_filter ($qmr_work_tag, 'wptexturize'); }

当然,你还可以将上面的代码分别下面的形式:

1
2
/取消内容转义 
remove_filter('the_content', 'wptexturize');//取消摘要转义remove_filter('the_excerpt', 'wptexturize');//取消评论转义 remove_filter('comment_text', 'wptexturize');

/取消内容转义 remove_filter('the_content', 'wptexturize'); //取消摘要转义 remove_filter('the_excerpt', 'wptexturize'); //取消评论转义 remove_filter('comment_text', 'wptexturize');

如果不想修改代码的,直接下载安装 Quotmarks Replacer 插件

上一篇:WordPress图片灯箱效果插件:Auto Highslide(自动链接到原图)

下一篇:获取WordPress文章的第一个链接

网友评论