WPML
SignaturePHP
apply_filters( 'wpml_post_language_details', mixed $empty_value, int $post_id )

Description

Retrieve language information of a post by its ID.

The language information that is returned includes:

  • the post language 2-letter code,
  • the post locale,
  • the language text direction (True for RTL, False for LTR),
  • the post language translated name and native name and
  • whether the current language is different to the post language (True/False)

Arguments

  • $empty_valuemixedRequired

    This is normally the value the filter will be modifying. We are not filtering anything here so set this to NULL. This for the filter function to actually receive the full argument list
  • $post_idintOptional

    The post id to retrieve information of (post, page, attachment, custom post) Defaults to current post ID.

Example Usage

In the example below we use the filter to retrieve the language information for the “Hello World” post.
The original language of the post is English and we have translated it to German.

PHP
$my_post_language_details = apply_filters( 'wpml_post_language_details', NULL, 1 ) ;

The above will return the following on the English version of the site:
PHP
array (
 'language_code' => 'en',
 'locale' => 'en_US',
 'text_direction' => false,
 'display_name' => 'English',
 'native_name' => 'English',
 'different_language' => false,
)

If we switch to the German version of the site we will see the following:
PHP
array (
 'language_code' => 'de',
 'locale' => 'de_DE',
 'text_direction' => false,
 'display_name' => 'German',
 'native_name' => 'Deutsch',
 'different_language' => true,
)