Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 9 replies, has 2 voices.

Last updated by Bobby 2 years, 10 months ago.

Assigned support staff: Bobby.

Author Posts
October 10, 2017 at 6:47 am #1396184

Karl

Is there a way to display the name of the current language (ICL_LANGUAGE_NAME) as a menu header or on a page?

With a shortcode preferably?

October 10, 2017 at 10:30 am #1396512

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

Thank you for contacting WPML Support,

You could use wpml_language_switcher shortcode

ex.[wpml_language_switcher type="footer" flags=1 native=1 translated=1][/wpml_language_switcher]

This can be used inside the WordPress Post Editor to display a language switcher.

You can read more here regarding the shortcodes WPML supports
=> https://wpml.org/documentation/support/wpml-coding-api/shortcodes/

Furthermore you can find more information here regarding Hooks like the one listed in this thread "ICL_LANGUAGE_NAME"

Constant ICL_LANGUAGE_CODE
Description Code for the current language
Example fr

Constant ICL_LANGUAGE_NAME
Description Name of current language, in the current language
Example Français

Constant ICL_LANGUAGE_NAME_EN
Description Name of the current language name in English
Example French

-> https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

October 10, 2017 at 10:43 am #1396529

Karl

so I add this code to my themes function.php? How can I echo this language then in a page or menu?

$my_current_lang = apply_filters( 'wpml_current_language', NULL );

October 10, 2017 at 4:05 pm #1397079

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

To call it you would just echo it

echo $my_current_lang;
October 10, 2017 at 4:11 pm #1397088

Karl

I tried already, but does not work.

I put this in functions.php and tried to create a shortcode like this:

$my_current_lang = apply_filters( 'wpml_current_language', NULL );

function currentlangsc() {
echo $my_current_lang;
}
add_shortcode('currentlang', 'currentlangsc');

October 10, 2017 at 4:48 pm #1397156

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

To understand better ; you want to be able to display the name of the language that the user is viewing correct ?

You can do this using a language switcher and place it in a custom location , do you want to have this along with a language switcher?

As this is not a standard feature i would like to note that support is limited to providing a custom solution but i will try to help as much as possible

Kind Regards,
Bobby

October 10, 2017 at 5:02 pm #1397174

Karl

Correct, only the current language the user is watching. No switcher.

October 11, 2017 at 10:13 am #1397872

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

Go to your theme's footer.php or header.php and paste the following basic code to display it.

<?php
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
echo "the current lang is: " . $my_current_lang . " ";
?>

Note : You can change the code to your liking or add CSS to it. i am just providing a basic script.

The above code has been tested in my theme's footer.php and it works as expected (screenshot)

NoteII : remember to remove the code you added in the functions.php file its not needed since we are just including the hook to our script.

NoteIII : The specific hook displays the language code.

You can always make it into more sophisticated code with an If statement.

October 11, 2017 at 10:16 am #1397878

Karl

I am using Beaver Builder, so I need some kind of (short)code to put into a custom header field. Would that be possible?

October 11, 2017 at 11:19 am #1397951

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

This a hook that is meant to be used in your code.

I am not sure if you can add plain code within your beaver builder , like you mentioned a shortcode is needed.

You might be able to create a custom shortcode

You can read more here regarding the shortcodes WPML supports
=> https://wpml.org/documentation/support/wpml-coding-api/shortcodes/

This will require custom work
If you need custom programming work for your site, we recommend contacting one of our certified partners .

=> https://wpml.org/documentation/support/wpml-contractors/

Note : You could try to just add an HTML message in the custom header field, saying for ex. "ENGLISH" on the header of the English page and "SPANISH" for example for the secondary language.

Kind Regards,
Bobby