Use Baidu Translate to automatically translate WordPress Chinese titles into English as fixed links

888u

Last update at :2024-07-07,Edit by888u

Using Baidu Translation's translation API to automatically translate Chinese article titles into English. After testing, it is suitable for WordPress built-in article types and custom article types added by plug-ins such as bbPress, BuddyPress, WooCommerce, and DW Question Answer.

The code is as follows, just add it to the functions.php file of the current theme:

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 );

Reprinted from: https://jiub.ren/2923.html

Recommended site search: Hong Kong host, domain name registration official website, American and European cloud servers, registered domain names, all-purpose virtual hosts, space registration, Hong Kong cloud servers, free server website ip search, ip proxy server,

Use Baidu Translate to automatically translate WordPress Chinese titles into English as fixed links

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码