Chen Weiliang : What to do if the WP Slug Translate plugin is not working?
Add code to translate article alias to English
Since many online marketers use WordPress to build websites for online promotion , many install the WP Slug Translate plugin to solve the problem of automatically translating Chinese aliases into English aliases for articles.
However, now the website of the author of the WP Slug Translate plugin has been closed, indicating that the other party has given up maintaining this plugin.
In other words, all the WordPress plugins developed by the other party are no longer working...
However, we can use Baidu Translate's API to automatically translate WordPress Chinese article titles into English.
Add automatic translation of code
Just add it to the functions.php file of the current theme:
function translate_chinese_post_title_to_en_for_slug( $title ) {/*transtype:transrealtime*/$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 );
Chen Weiliang 's tests showed that adding the above code for automatically translating WordPress post aliases via Baidu significantly slows down the loading time when clicking "Publish," "Schedule," or "Update" in the post editor compared to not adding the code, and may even result in a 500 error.
(This issue may be related to the region where Chen Weiliang 's blog server is located.)
Or, you can test it yourself to see how?
Hopefully, the article "What to do if the WP Slug Translate plugin is not working? Add code to translate the article into English" shared on Chen Weiliang's blog ( https://www.chenweiliang.com/ ) will be helpful to you.
Feel free to share this article's link: https://www.chenweiliang.com/cwl-443.html
