wordpress 取消两个减号自动连接为破折号
解决方法如下:
一、禁用所有的 WP 转义
WordPress 自带一个专一的钩子wptexturize,很多地方都用到了这个钩子,具体可以在wp-includes/formatting.php中查看。我们可以在WordPress主题的functions.php文件中添加以下代码来取消掉这个转义:
add_filter( 'run_wptexturize', '__return_false' );
二、(推荐)调用remove_filter函数来移除wordPress对wptexturize的调用
这是最简单的方法,在主题目录下的functions.php文件中添加如下代码即可:
//取消网站标题转换 remove_filter('the_title', 'wptexturize'); //取消博客标题转换 remove_filter('wp_title', 'wptexturize'); //取消网站摘要转换 remove_filter('the_excerpt', 'wptexturize'); //取消正文内容转换 remove_filter('the_content', 'wptexturize'); //取消文章标题转换 remove_filter('single_post_title', 'wptexturize'); //取消评论内容转换 remove_filter('comment_text', 'wptexturize'); //取消评论作者转换 remove_filter('comment_author', 'wptexturize'); //取消分类描述转换 remove_filter('category_description', 'wptexturize'); //取消侧栏标题转换 remove_filter('widget_title', 'wptexturize'); //取消侧栏内容转换 remove_filter('widget_text', 'wptexturize'); //取消友链描述转换 remove_filter('link_description', 'wptexturize');
三、直接注释
在用wordpress时,你可能会发现这个问题,我明明写文章时,用的是破折号,也就是两个减号(--),为何发表文章时,成了一个减号(-)呢?原来这是wordpress的代码问题。
在 wp-includes/formatting.php 的文件中,在56行有这么的一句使得输入的连字符被自动替换成破折号:
//$static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
本文作者:𝙕𝙆𝘾𝙊𝙄
文章名称:WordPress英文字符源代码转义成中文字符教程
文章链接:https://www.zkcoi.com/365up/program/2430.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。