WordPress函数wptexturize用法

简介

将纯文本字符转换成格式化的 HTML 实体。<PRE>,<CODE>,<kbd>,<STYLE>,<script>和<tt>中的文本被忽略。

用法

<?php wptexturize( $text ); ?>

参数

$text
(string) (required) 将被格式化的文本
Default: None

返回值

(string)
被替换成HTML数字实体字符的文本。

注解

开启和关闭引号将在 WordPress 翻译文件中被定义,下面是 wptexturize 做的转换。

原始文本 转换之后的文本 符号名称
"---" "—" em-dash | 破折号
" -- " "—" em-dash | 破折号
"--" "–" en-dash | 连接号
" - " "–" en-dash | 连接号
"xn–" "xn--"
"..." "…" ellipsis | 省略号
`` opening quote | 开启引号
'' closing quote | 关闭引号
" (tm)" " ™" trademark symbol | 注册商标符号
1234" 1234″ double prime symbol | 双撇号
1234' 1234′ prime symbol | 撇号
1234x1234 1234×1234 multiplication symbol | 乘法符号

使用实例:

禁止WordPress将英文半角符号转换成全角符号

在主题function.php文件中添加如下函数:

$qmr_work_tags = array(
  'the_title',             // 标题
  'the_content',           // 内容 *
  'the_excerpt',           // 摘要 *
  'single_post_title',     // 单篇文章标题
  'comment_author',        // 评论作者
  'comment_text',          // 评论内容 *
  'link_description',      // 友链描述(已弃用,但还很常用)
  'bloginfo',              // 博客信息
  'wp_title',              // 网站标题
  'term_description',      // 项目描述
  'category_description',  // 分类描述
  'widget_title',          // 小工具标题
  'widget_text'            // 小工具文本
  );
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');

原文来自:

http://www.aimks.com/wordpress-is-prohibited-from-english-half-symbol.html

http://blog.wpjam.com/function_reference/wptexturize/