今天客户的網站剛用到的,記錄一下,以後就知道了。菜單選項的轉義用 the_title 即可解決。

WordPress 模式使用了 wptexturize 函數將純文本字符轉換成格式化的 HTML 實體。

標籤 <pre>, <code>, <kbd>, <style>, <script> 和<tt> 中的文本被忽略。

對於一般寫單純碼文字的人來説,這個自動將英文半角符號轉換成全角符號,是很方便、智能。

但如果你經常要粘貼一些代碼,而且沒有使用專門的代碼高亮插件,你會發現,你代碼中的半角符號都會被轉換成全角了!別人複製後,根本沒辦法直接使用!

禁止字符轉義的所有代碼如下,你可以根據自己的需要,選自己要的代碼,添加到主題的 functions.php 文件:

// 取消轉義 Quotmarks Replacer
$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');
}

當然,你還可以將上面的代碼分別下面的形式:

/取消內容轉義
remove_filter('the_content', 'wptexturize');
//取消摘要轉義
remove_filter('the_excerpt', 'wptexturize');
//取消評論轉義
remove_filter('comment_text', 'wptexturize');

如果不想修改代碼的,直接下載安裝 Quotmarks Replacer 插件。