当前所在位置: 首页>>百科全书

WordPress取消英文标点符号自动替换中文标点符号的优雅方法

发布时间:2025-10-23 09:53:25 本站作者 【 字体: 】 浏览:95 次

众所周知,WordPress中文版有个特性,会将每一处英文引号("")都稀里哗啦转化为中文引号(“”)。不仅仅是英文引号,在WordPress翻译文件定义了不少自动转换符号,具体可以参考这里

对文字博客来说,这是个好功能,这样会避免用错英文标点。

然而,WordPress是独立的php程序,中文社区中懂得使用者,大部分都是技术博客。而技术博客会经常贴出代码,里面包含各种英文标点是再正常不过的事情。这时候,英文标点符号自动转换就是一个恼人的画蛇添足功能了。

网上很多文章都是让该WordPress核心文件。只不过,WordPress是一个高度模块化的系统,肯定有更优雅的解决方案。

一番搜寻之后,发现最简单的办法,就是安装一个叫Quotmarks Replacer的插件,地址在这里

插件很简单,就是将WordPress自动转换标点符号的函数用系统接口去掉。核心代码如下:

<?php
/*
Plugin Name: Quotmarks Replacer
Plugin URI: http://sparanoid.com/work/quotmarks-replacer/
Description: Quotmarks Replacer disables wptexturize function that keeps all quotation marks and suspension points in half-width form.
Version: 2.6.17
Author: Tunghsiao Liu
Author URI: http://sparanoid.com/
Author EmAIl: t@sparanoid.com
License: GPLv2 or later
Copyright 2016 Tunghsiao Liu, aka. Sparanoid (t@sparanoid.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
$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');
}

当然你也可以参考这篇文章:https://www.freexyz.cn/cms/bee94fdf6816331685a559f0aec28cfd.html


上一篇:如何手动将本地WordPress站点迁移到主机/服务器?

下一篇:Win10电脑skype一直转圈登录不了怎么办?

最新发布
猪血炒白菜怎么做_猪血炒白菜的做法窍门

猪血炒白菜怎么做_猪血炒白菜的做法窍门

猪血炒白菜怎么做_猪血炒白菜的做法窍门
猪血炒白菜是一道家常美味菜肴,它不仅口感丰富,营养也较为均衡。要做出美味的猪血炒白菜,掌握其做法窍门很关键。首先准备食材,新鲜的猪血、白菜、葱姜蒜等必不可少。猪血最好选用质地细腻、无异味的,这样炒出的口感才好。白菜则要挑选叶片嫩绿、菜帮脆嫩的,将其洗净后切成适当大小。葱姜蒜切成末或丝备用,同时准备好...
炒包菜教程_请问炒包菜怎么炒

炒包菜教程_请问炒包菜怎么炒

炒包菜教程_请问炒包菜怎么炒
炒包菜是一道简单又美味的家常菜肴,它以其清爽可口的口感和丰富的营养价值深受人们喜爱。要炒出一盘美味的包菜,需要掌握一些技巧和方法。准备好新鲜的包菜,将其洗净切成适当大小的块状。接着,准备好葱姜蒜等调料,为菜肴增添香味。在炒制过程中,火候的掌握至关重要,要根据包菜的特点和个人口味来调整。调料的使用也不...
绿豆炒鸡蛋怎么做_鸡蛋炒豆角做法

绿豆炒鸡蛋怎么做_鸡蛋炒豆角做法

绿豆炒鸡蛋怎么做_鸡蛋炒豆角做法
在美食的世界里,绿豆炒鸡蛋与鸡蛋炒豆角都是备受青睐的佳肴。它们不仅制作过程充满乐趣,还能为我们带来独特的味觉享受。下面就为大家详细介绍这两道美味菜肴的做法。绿豆炒鸡蛋,首先要准备好适量的绿豆、鸡蛋以及葱、盐、油等调料。绿豆需提前浸泡一段时间,这样能让它在炒制时更容易熟透。浸泡好后,将绿豆捞出沥干水分...
山西炒莜面怎么炒好吃又简单_家常炒莜面做法窍门

山西炒莜面怎么炒好吃又简单_家常炒莜面做法窍门

山西炒莜面怎么炒好吃又简单_家常炒莜面做法窍门
山西炒莜面是一道美味独特的家常菜肴,它不仅有着浓郁的地方特色,还因其丰富的口感和相对简单的制作方法深受人们喜爱。想要做出好吃又简单的山西炒莜面,掌握一些做法窍门是关键。准备好优质的莜面。莜面的品质直接影响着炒莜面的口感,要选择颗粒饱满、色泽纯正的莜面。将莜面适量放入盆中,加入适量的开水,边加边搅拌,...