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 3 replies, has 2 voices.

Last updated by Andreas Neuber 8 years, 7 months ago.

Assigned support staff: Andreas Neuber.

Author Posts
January 25, 2013 at 3:52 pm #99414

Ad Label


I am having trouble in trying to change the language in my code , just like this thread:

I have trien following the stepf here but no luck. Here's my code:

add_action('after_setup_theme', 'my_icl_set_current_language');

function my_icl_set_current_language() {
$lang = $_GET['lang'];
global $sitepress;

The ICL_LANGUAGE_CODE constant never changes to the desired language.

Can you please provide some help?

Thanks in advance,


January 25, 2013 at 5:20 pm #99455

Andreas Neuber

Languages: English (English ) German (Deutsch )

Hello AdLabel,

The code looks altogether correct. The constant ICL_LANGUAGE_CODE will have as its value the default language set.
So for your tests you would rather need to use a...


Do you need this function for AJAX?

January 29, 2013 at 4:50 pm #100271

Ad Label


Yes, this is to be used in ajax.

In your documentation it reads that ICL_LANGUAGE_CODE holds the current language, shouldn't it reflect the language we chose?

January 30, 2013 at 8:17 am #100401

Andreas Neuber

Languages: English (English ) German (Deutsch )

Hello AdLabel,

The problem here is that the value of constant ICL_LANGUAGE_CODE is set when the instance of the sitepress class is created. Or in other words, its value changes only with a new page call.


// part of SitePress class definition
    define('ICL_LANGUAGE_CODE', $this->this_lang);

However, with AJAX you are not calling the website new in the browser, just a part of it (the basic concept of AJAX).

The topic ‘[Closed] Change language programaticly’ is closed to new replies.