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 1 reply, has 2 voices.

Last updated by Bruno 5 years, 4 months ago.

Assigned support staff: Bruno.

Author Posts
January 23, 2015 at 1:08 am #547598

sebastianM-7

Hi there,

I am trying to have different code selected dependent on the language selected and have used Robert's suggested code. Somehow however, the switcher is not working. I have use the exact code Rober provided and that is outlined in the guide. Have I forgotten something? See code below:
<?php if(ICL_LANGUAGE_CODE=='nz'): ?>
ga('create', 'UA-51097835-1', 'auto');
<?php elseif(ICL_LANGUAGE_CODE=='eur'): ?>
ga('create', 'UA-51097835-2', 'auto');
<?php elseif(ICL_LANGUAGE_CODE=='de'): ?>
ga('create', 'UA-51097835-3', 'auto');
<?php elseif(ICL_LANGUAGE_CODE=='aus'): ?>
ga('create', 'UA-51097835-5', 'auto');
<?php endif; ?> -->

Many thanks in advance.
Regards,
Sebastian

P.S. - Roberts advice:
Hi Minesh,

Thank you so much for all your good work. that is absolutely amazing! Loving it!
On question that I have which is related is, is there a way to have variables that you set for each language and dependent on the language selected, it will give back the right text. E..g I use a viable $phone on a page that is duplicated in all english languages (so content is identical in all cases), however the variable $phone changes depended to the language selected. Possible? Do you have a guide on that? Many thanks in advance and have the best day ever!
Regards,
Sebastian

JANUARY 14, 2015 AT 2:54 PM #542462 REPLY

Robert
Forum moderator

Minesh is away on holiday so I will take his place for now. Glad you were able to resolve the issue, as for the new question. You can use WPML api to show content based on the active language like so:

1
2
3
4
5
<?php if(ICL_LANGUAGE_CODE=='en'): ?>
---do something---
<?php elseif(ICL_LANGUAGE_CODE=='nl'): ?>
---do something else--
<?php endif; ?>
More information here: http://wpml.org/documentation/support/wpml-coding-api/
I expected to see:

Instead, I got:

January 23, 2015 at 4:23 pm #548058

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

In the code you mentioned above, has two conditional:

<?php elseif(ICL_LANGUAGE_CODE=='eur'): ?>
<?php elseif(ICL_LANGUAGE_CODE=='aus'): ?>

The ICL_LANGUAGE_CODE constant check the language code. You have these language code: eur and aus?

Also, this code is not working in any language?

Thank you.

The topic ‘[Closed] php code for manual language switcher not working?’ is closed to new replies.