wordpress取消自动替换字符串
在wordpress显示内容的时候,发现会自动把“–”替换成“-”
这个在有些时候很不爽,比如实际上想显示 ./configure –help 实际却显示 ./configure -help
于是乎查看wp的源代码,终于找到根源了,
在wp-includes/formatting.php这个文件中
找到wptexturize这个函数,
在这个函数里面再找到如下代码,
- $static_characters = array_merge(array('---', ' -- ', '--', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $co
- ckney);
把这行注释起来就好了。
- //$static_characters = array_merge(array('---', ' -- ', '--', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $co
- ckney);
另外,紧接着下面的一行
- $static_replacements = array_merge(array('—', ' — ', '–', 'xn--', '…', '“', '’s'
- , '”', ' ™'), $cockneyreplace);
把这行也注释起来。。。
取而代之的是:
- $static_characters = array("");
- $static_replacements = array("");
或者更直接,在函数声明后面直接加上:
- function wptexturize($text) {
- return $text;
- ......
- }
另外,如果你的wordpress版本比较老,例如1.x的版本,
则需要在 wp-includes/functions-formatting.php中找到wptexturize这个函数
找到类似于
- $curl = str_replace('---', '—', $curl);
- $curl = str_replace(' -- ', ' — ', $curl);
- $curl = str_replace('--', '–', $curl);
- $curl = str_replace('xn–', 'xn--', $curl);
- $curl = str_replace('...', '…', $curl);
- $curl = str_replace('``', '“', $curl);
这样的代码,进行注释
tags: wordpress
