根据documentation 这里有3个Polylang函数可以帮助您:
第一个“记住”用户语言的人
pll_current_language
// Returns the current language
pll_current_language( $value );
// ‘$value’ => (optional) either ‘name’ or ‘locale’ or ‘slug’, defaults to ‘slug’
returns either the full name, or the WordPress locale (just as the WordPress core function ‘get_locale’ or the slug ( 2-letters code) of the current language.
现在这一个来检查他单击的页面是否存在用户语言
pll_get_post_translations
// Returns an associative array of translations with language code as key and translation post_id as value
pll_get_post_translations( $post_id );
// ‘$post_id’ => (required) id of the post for which you want to get the translations
如果找到了用户语言,请立即获取翻译后的帖子
pll_get_post
pll_get_post( $post_id, $slug );
// ‘$post_id’ => (required) id of the post you want the translation
// ‘$slug’ => (optional) 2-letters code of the language, defaults to current language
最后一个
$slug
对你来说不是可选的