使用 WordPress 以來,總是很討厭它把一些符號自動替換掉,例如會把 ‘ 換成 html entities 。
在網路上找到一些方法,大多都是修改 wp-includes/formatting.php 來處理文字替換 (大概在 5x 行的地方)
1 2 3 4 |
$static_characters = array_merge( array(/*'---', ' -- ', '--', ' - ', 'xn–',*/ '...', '``', '\'\'', ' (tm)'), $cockney ); $static_replacements = array_merge( array(/*$em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--',*/ '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace ); |
但我總覺得這樣不太好,因為這種改法每升級一次就得改一次,實在是太蠢了。
後來我找到比較正確的解法:編輯佈景主題裡面的 functions.php 並加入以下程式碼:
1 2 3 4 5 6 |
remove_filter('the_content', 'wptexturize'); remove_filter('the_excerpt', 'wptexturize'); remove_filter('comment_text', 'wptexturize'); remove_filter('the_title', 'wptexturize'); |
總算解決了符號自動替換的問題。