• Resolved pipoulito

    (@pipoulito)


    Hi,

    In a function in functions.php i need to detect the language of the page , is there a function to do that please ?

    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.
    Thread Starter pipoulito

    (@pipoulito)

    yes that’s it !! merci beaucoup ?? !!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Detect language page in code’ is closed to new replies.