将代码加到主题functions.php即可,原理很简单,就是使用百度翻译的接口
function uctheme_slug_auto_translate( $title ) { $wp_http_get = wp_safe_remote_get( 'http://fanyi.baidu.com/v2transapi?from=zh&to=en&transtype=trans&query=' . $title ); 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; } add_filter( 'sanitize_title', 'uctheme_slug_auto_translate', 1 );
扔到主题的function.php里去!
外贸使用这个很方便,但是需要家个截断,要不然文章名太长也不利于seo