Skip to main content
added 378 characters in body
Source Link
Core972
  • 126
  • 1
  • 1
  • 8

According to the documentation there are 23 Polylang functions that can help you here :

The first to "remember" the user language.

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.

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.

Now this one to check if the user language exist for the page he clicked

pll_get_post_languagepll_get_post_translations

pll_get_post_language// Returns an associative array of translations with language code as key and translation post_id as value
pll_get_post_translations( $post_id, $field );
 
// ‘$post_id’ => (required) id of the post for which you want to get the languagetranslations

Now if the user language have been found get the translated post

pll_get_post

pll_get_post( $post_id, $slug );

// ‘$field’‘$post_id’ => (optionalrequired) eitherid ‘name’of orthe ‘locale’post oryou ‘slug’want the translation
// ‘$slug’ => (optional) 2-letters code of the language, defaults to ‘slug’current language

For the last one $slug isn't optional for you

According to the documentation there are 2 Polylang functions that can help you here :

The first to "remember" the user language.

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.

Now this one to check if the user language exist for the page he clicked

pll_get_post_language

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’

According to the documentation there are 3 Polylang functions that can help you here :

The first to "remember" the user language.

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.

Now this one to check if the user language exist for the page he clicked

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

Now if the user language have been found get the translated post

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

For the last one $slug isn't optional for you

Source Link
Core972
  • 126
  • 1
  • 1
  • 8

According to the documentation there are 2 Polylang functions that can help you here :

The first to "remember" the user language.

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.

Now this one to check if the user language exist for the page he clicked

pll_get_post_language

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’