本来之前是用插件来做的,无奈换了主题后英文和拼音插件都无效,最后不得不改用手动输入,今天无意发现这个方法。采用百度翻译的翻译API,将中文的文章标题自动翻译为英文。
代码如下,添加到当前主题的 functions.php 文件即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function translate_chinese_post_title_to_en_for_slug( $title ) { /* transtype: trans realtime */ $translation_render = 'http://fanyi.baidu.com/v2transapi?from=zh&to=en&transtype=realtime&simple_means_flag=3&query='.$title; $wp_http_get = wp_safe_remote_get( $translation_render ); if ( empty( $wp_http_get->errors ) ) { if ( ! empty( $wp_http_get['body'] ) ) { $trans_result = json_decode( $wp_http_get['body'], true ); $trans_title = $trans_result['trans_result']['data'][0]['dst']; return $trans_title; } } return $title; } add_filter( 'sanitize_title', 'translate_chinese_post_title_to_en_for_slug', 1 ); |

还是喜欢人工自己写
人工有时太麻烦,特别是用手机而标题又长时!
这个....译个标题何用? 文章链接么....
P.S. Lvtu兄又折腾一番, 换了个样式啦, 挺好看....
就是文章链接要用呀,不然就是数字之类的!