WordPress建站中开启固定链接,自动翻译中文文章标题为英文

wordpress建站过程中,中文站点里当我们开启固定链接并且使用文章标题作为链接时,链接经常会变得非常长,看起来很不美观,而且对收录也不是太友好。这时候我们可以采用百度翻译的翻译API,将中文文章标题自动翻译为英文。

使用方法如下,切换到主题目录,打开functions.PHP文件,加入以下代码

Crayon-5c891d3f50fe6733644359" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-2">2
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-4">4
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-6">6
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-8">8
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-10">10
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-12">12
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-14">14
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-16">16
Crayon-num" data-line="Crayon-5c891d3f50fe6733644359-17">17
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3f50fe6733644359-18">18
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d3f50fe6733644359-1">Crayon-t">functionCrayon-h"> Crayon-e">translate_chinese_post_title_to_en_for_slugCrayon-sy">(Crayon-h"> Crayon-sy">$Crayon-i">titleCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-2">Crayon-h">Crayon-c">/*
Crayon-line" id="Crayon-5c891d3f50fe6733644359-3">Crayon-c">transtype:
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-4">Crayon-c">trans
Crayon-line" id="Crayon-5c891d3f50fe6733644359-5">Crayon-c">realtime
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-6">Crayon-c"> */
Crayon-line" id="Crayon-5c891d3f50fe6733644359-7">Crayon-h">Crayon-sy">$Crayon-v">translation_renderCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'http://fanyi.baidu.com/v2transapi?from=zh&to=en&transtype=realtime&simple_means_flag=3&query='Crayon-sy">.Crayon-sy">$Crayon-v">titleCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-8">Crayon-h">Crayon-sy">$Crayon-v">wp_http_getCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">wp_safe_remote_getCrayon-sy">(Crayon-h"> Crayon-sy">$Crayon-v">translationCrayon-sy">_renderCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d3f50fe6733644359-9">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">emptyCrayon-sy">(Crayon-h"> Crayon-sy">$Crayon-v">wp_http_getCrayon-i">errorsCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-10">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-o">!Crayon-h"> Crayon-e">emptyCrayon-sy">(Crayon-h"> Crayon-sy">$Crayon-v">wp_http_getCrayon-sy">[Crayon-s">'body'Crayon-sy">]Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d3f50fe6733644359-11">Crayon-h">Crayon-sy">$Crayon-v">trans_resultCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">json_decodeCrayon-sy">(Crayon-h"> Crayon-sy">$Crayon-v">wp_http_getCrayon-sy">[Crayon-s">'body'Crayon-sy">]Crayon-sy">,Crayon-h"> Crayon-t">trueCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-12">Crayon-h">Crayon-sy">$Crayon-v">trans_titleCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">trans_resultCrayon-sy">[Crayon-s">'trans_result'Crayon-sy">]Crayon-sy">[Crayon-s">'data'Crayon-sy">]Crayon-sy">[Crayon-cn">0Crayon-sy">]Crayon-sy">[Crayon-s">'dst'Crayon-sy">]Crayon-sy">;
Crayon-line" id="Crayon-5c891d3f50fe6733644359-13">Crayon-h">Crayon-st">returnCrayon-h"> Crayon-sy">$Crayon-v">trans_titleCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-14">Crayon-h">Crayon-sy">}
Crayon-line" id="Crayon-5c891d3f50fe6733644359-15">Crayon-h">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-16">Crayon-h">Crayon-st">returnCrayon-h"> Crayon-sy">$Crayon-v">titleCrayon-sy">;
Crayon-line" id="Crayon-5c891d3f50fe6733644359-17">Crayon-sy">}Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d3f50fe6733644359-18">Crayon-e">add_filterCrayon-sy">(Crayon-h"> Crayon-s">'sanitize_title'Crayon-sy">,Crayon-h"> Crayon-s">'translate_chinese_post_title_to_en_for_slug'Crayon-sy">,Crayon-h"> Crayon-cn">1Crayon-h"> Crayon-sy">)Crayon-sy">;

相关文章

WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的...
这两段代码可以让你先体验一下WordPress 3.0的菜单样式 首先在functions.php添加如下代码: register_n...
有人说 WordPress 本身的 SEO 就比较好,我想这个和 WordPress 可以方便的自定义文章的固定链接有分不开...
曾经给大家介绍了在 WordPress 后台移除主题编辑器,今天继续加深,直接关闭 WordPress 后台的文件编辑...
WordPress之iNove主题内容页增加公告栏的方法,导航栏下面默认的公告栏只能在首页显示,只要修改一个文...
大多数WordPress用户都知道该怎么从数千个WordPress主题里挑出自己喜欢,但要自己开发新主题恐怕不是人...