Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client needed a solution for inserting different affiliate codes for each language in their posts without losing changes after updates or re-translations. The affiliate codes were not appearing in the ATE translator as regular text links, and manual replacements were being overwritten with updates.
Solution:
We recommended using a custom PHP snippet or shortcode that dynamically inserts the affiliate code based on the current language. This approach ensures that the correct widget appears automatically for each language version and remains unchanged after updates or re-translations. Here is an example of how you might set this up:

function cityxee_viator_widget() {<br />    if (defined('ICL_LANGUAGE_CODE')) {<br />        switch (ICL_LANGUAGE_CODE) {<br />            case 'da':<br />                return 'kode til dansk viator';<br />            case 'en':<br />                return 'kode til engelsk viator';<br />            case 'fr':<br />                return 'kode til fransk viator';<br />        }<br />    }<br />}<br />add_shortcode('cityxee_viator', 'cityxee_viator_widget');

For posts requiring unique codes, we suggested using a custom field to store the affiliate ID, which can then be dynamically inserted into the affiliate widget code for each post:

<?php<br />$idkey = get_field('acf_partner_id'); // or whatever your field name is<br />?><br /><div data-vi-partner-id="<?php echo esc_attr($idkey); ?>" data-vi-widget-ref="W-6712b6be-d928-47db-b9a6-c96bce812859"></div><br /><script async src="https://www.viator.com/orion/partner/widget.js"></script>

If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket at WPML support forum.

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 5 replies, has 0 voices.

Last updated by Dražen 2 months, 3 weeks ago.

Assisted by: Dražen.

Author Posts
November 10, 2025 at 10:21 am #17561391

simonB-10

Hi Drazen,

Thank you very much for the fix - now all the jobs get finished/pencil-symbol. 🙂

1) In all the posts there is a section in which an HTML widget is inserted with most often a Viator affiliate code - as you have seen - e.g.:

"<div data-vi-partner-id="P00095673" data-vi-widget-ref="W-6712b6be-d928-47db-b9a6-c96bce812859"></div>
<script async src="hidden link"></script>"

2) These Affiliate codes are different for each language (in our case EN and FR)
3) Since they do not appear in the ATE translator as regular text links, I have to go into the individual post and replace the Danish affiliate code with an En and FR respectively
4) If I then make an update in the Danish language that takes effect in the other languages ​​(as it should), the English and French affiliate code is overwritten with the Danish one, and then I have to edit them individually again.

Is there a work-around for this?

November 10, 2025 at 10:26 am #17561474

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

This behavior is expected — HTML content like your Viator affiliate widgets shouldn’t be translated they should be same, and if you need different content code then different approach should be taken in consideration.

Mixing manual edits with automatic (ATE) translations can cause synchronization issues, where changes made in one language overwrite the others. You should either use ATE editor or manual approach, not both.

I think the best approach is to insert the affiliate code dynamically — for example, by using a custom PHP snippet or shortcode that displays a different code depending on the current language. That way, the correct widget appears automatically for each language version, and you won’t lose your changes after updates or re-translations.

Hope this helps.

Regards,
Drazen

November 11, 2025 at 7:18 am #17564799

simonB-10

Hi Drazen,

We need/it is different content code for each language.

"I think the best approach is to insert the affiliate code dynamically — for example, by using a custom PHP snippet or shortcode that displays a different code depending on the current language. That way, the correct widget appears automatically for each language version, and you won’t lose your changes after updates or re-translations."

I understand and something like:

elementor html-widget: [cityxee_viator]

function cityxee_viator_widget() {
if ( defined('ICL_LANGUAGE_CODE') ) {
switch (ICL_LANGUAGE_CODE) {
case 'da':
return ' kode til dansk viator ';
case 'en':
return ' kode til engelsk viator ';
case 'fr':
return ' kode til fransk viator ';
}
}
}
add_shortcode('cityxee_viator', 'cityxee_viator_widget');

But what if this code is not only unique for each language but each post too?

November 11, 2025 at 7:57 am #17564961

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for getting back.

Yes, that it what I was thinking.

As for post then probably best different approach, I guess code it is not different in whole but just some part, for example ID, then you can code that part to change dynamically also etc. For example custom field is set in each post which is then added to your code for that post etc.

Rough example of code:

<?php
$idkey = get_field('acf_partner_id'); // or whatever your field name is
?>
<div data-vi-partner-id="<?php echo esc_attr($idkey); ?>" data-vi-widget-ref="W-6712b6be-d928-47db-b9a6-c96bce812859"></div>
<script async src="<em><u>hidden link</u></em>"></script>

But this all includes custom coding and best to advise with developer.

Hope this helps.

Regards,
Drazen

November 17, 2025 at 7:30 am #17582536

simonB-10

Hi Drazen,

I wanted to write thank you for your great help. 🙂

Your code example makes perfect sense and I see now how this can me solved.

November 17, 2025 at 8:35 am #17582705

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

great, thank you!:)

Glad I was able to help.

Feel to contact us again if there is anything we can do for you.

Kind regards,
Drazen