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.
Tagged: Custom Work
This topic contains 3 replies, has 2 voices.
Last updated by Nicolas V. 1 year, 7 months ago.
Assisted by: Nicolas V..
Author | Posts |
---|---|
October 31, 2023 at 4:05 pm #14702155 | |
eikoT |
Hi, I'm currently developing a new custom theme. The use of constants like ICL_LANGUAGE_CODE is flagged as deprecated in your docs. However I want to use the old ICL_LANGUAGE_NAME constant to simply get the current language name written out in the current language. As in 'English' or 'Deutsch'. Any suggestions? Kind Regards |
October 31, 2023 at 8:47 pm #14703883 | |
Nicolas V. Supporter
Languages: English (English ) French (Français ) Timezone: America/Lima (GMT-05:00) |
Hello, Welcome to the WPML support forum. $my_current_lang = apply_filters( 'wpml_current_language', NULL ); if ( $my_current_lang == 'fr' ){ [FRENCH TEXT HERE] } elseif ( $my_current_lang == 'en' ){ [FRENCH TEXT HERE] Ref: https://wpml.org/wpml-hook/wpml_current_language/ 2. Or use 'wpml_post_language_details' to get all the details about the language of a post (this will include the translated and the native names: French / Français). |
November 1, 2023 at 10:14 am #14706507 | |
eikoT |
Thanks for your reply. 1. Sorry, this is too crude for my case. If I add another language this solution falls apart. 2. I've looked into that, but this filter needs a post object. That means, on a 404 Page this filter throws a wp error object. I've found another filter called 'wpml_active_languages' that enabled me to build my own template function. Maybe add something like that to your FAQ / Docs. Feel free to use my function. Here's a gist: hidden link ```php foreach ($wpml_active_languages as $key => $language) { The issue is resolved now. |
November 1, 2023 at 12:27 pm #14707361 | |
Nicolas V. Supporter
Languages: English (English ) French (Français ) Timezone: America/Lima (GMT-05:00) |
Hello, I'm sorry if I didn't fully understand your request. I thought you were building a custom theme for yourself. You can find all our hooks here: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/ I hope it will be helpful for you or any client finding this thread. Thanks for sharing your solution! I'll close this ticket now, but feel free to open a new ticket anytime you have questions, we will be happy to help. Have a good day ahead, Bye 🙂 |