将代码加到主题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 );
原理就是通过百度翻译的接口,自动翻译你填写的文章名,不过看着如果文章名长的话,别名也很长啊!
WordPress插件
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
