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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Noman 1 year, 11 months ago.

Assisted by: Noman.

Author Posts
March 11, 2023 at 10:47 am #13222647

kelvinL-3

I love coding, I have a site with two languages, and I have a button; if the user has not yet login, the user will be redirected to /my-account and display 'Please login', otherwise, button will show 'My Dashboard' and the user will be redirected to /dashboard

After installing the WPML, I need to get the lang code and change the url, could you advise how I can do that?

March 12, 2023 at 9:54 am #13225117

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting WPML Support. You may use the wpml_current_language hook in PHP files to get the current language code and display the content accordingly. Here is an example of a condition:

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

if( $my_current_lang == 'fr' ) {
 	echo 'French language content goes here';
}
elseif( $my_current_lang == 'en') {
	echo 'English language content goes here';	
}

You may update it according to your needs.

Here docs docs for more details:
https://wpml.org/wpml-hook/wpml_current_language/
https://wpml.org/faq/how-to-get-current-language-with-wpml/

Please let me know if this resolves your issue or if you need further assistance.

Thank you