如果您想从您的网站上找到特定语言的 URL,我们有一个代码可以帮助您做到这一点:
<?php
/*
* Function to return the url for a particular language.
* Pass the desired language and the URL.
*/
function trpc_get_url_for_language($lang = null, $url = null) {
if ( ! class_exists('TRP_Translate_Press') )
return $url;
$trp = TRP_Translate_Press::get_trp_instance();
$url_converter = $trp->get_component( 'url_converter' );
return esc_url( $url_converter->get_url_for_language( $lang, $url, '' ) );
}
/*
* Shortcode to display the URL in another language:
* [url_for_lang lang="en_US" url="https://example.com/ro/pagina-de-test"]
*/
function shortcode_trpc_get_url_for_language($atts){
$atts = shortcode_atts( array(
'lang' => null,
'url' => null
), $atts, 'url_for_lang' );
return trpc_get_url_for_language($atts['lang'],$atts['url']);
}
add_shortcode( 'url_for_lang', 'shortcode_trpc_get_url_for_language' );
此代码适用于次要语言以及您网站上的默认语言。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容