For me it’s not 100% clear if you want to get the current language (set by user or automatically set by polylang for that user) or if you want to get the language of a particular page?
For case 1) there is:
pll_current_language
Returns the current language
Usage:
1
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.
For case 2) there is:
pll_get_post_language
gets the language of a post or page (or custom post type post)
Usage:
1
pll_get_post_language($post_id, $field);
‘$post_id’ => (required) id of the post for which you want to get the language
‘$field’ => (optional) either ‘name’ or ‘locale’ or ‘slug’, defaults to ‘slug’
returns either the full name, or the WordPress locale or the slug ( 2-letters code) of the post.
Both can be found here:
https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/
-
This reply was modified 7 years, 4 months ago by
ronhard.