This thread is resolved. Here is a description of the problem and solution.
Problem: You are developing a site using WPML's auto-translate feature and have encountered an issue where links within content translated using the Advanced Custom Fields (ACF) remain in the original language and point to the main language pages. Solution: To resolve this issue, you need to modify your template code to ensure that links are correctly translated and point to the appropriate language versions. Here is a step-by-step guide:
Ensure that your ACF link field is set to 'Translate' to allow for the translation of the link URL and text.
Modify your template code to use the
wpml_permalink
filter for translating the URL, and the
wpml_translate_string
filter for translating the link title. Here is an example of how you can implement this:
Adjust the return value of the link field to 'Link URL' to ensure the correct data type is used for URLs.
Please note that this solution might be outdated or not applicable to your specific case. If this solution does not resolve your issue, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket.
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.
I've created 2 new pages: test-page-1 and test-page-2. Did all the steps and the link still points to main language. Link in previous message is acf link field, which is children of block, that is childern of Flexible Content
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Hi,
I would like to offer to take a closer look and request temporary access (wp-admin and FTP) to the site to investigate the issue further.
The required fields are below the comment section when you log in to leave the next reply. The information you provide is private, meaning only you and I can see and access it.
IMPORTANT
Please be sure to back up the site and database before granting us access.
If you can't see the "wp-admin / FTP" fields, your post and site login details will be set to "PUBLIC". DO NOT publish the data unless you see the required wp-admin / FTP fields.
The private reply form looks like this: hidden link
The next time you reply, click on "I still need assistance".
Video: hidden link
Please note that we are obliged to request this information individually on each ticket. We are not allowed to access any credentials that were not specifically submitted on this ticket in the private response form.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Your field groups are not configured correctly.
Repeater Fields, Groups, and Flexible content fields need to be set to "Copy once" or "Copy".
All your fields are set to "Not translate".
As long as a field is set to "Not translate", nothing will happen if you translate the page. You need to set the link fields to "Copy" to copy the link or to "Translate" to translate the link.
1. Set a "Flexible Content" field to "Copy".
2. Within the "Stats Banner" (a flexible content block), the "Colour Box" group and the "link" field inside it were set to "Copy".
3. Created a new page: "weekend-test-page" (hidden link) and translated it.
4. Created another page: "weekend-test-page-2"(hidden link), added the "Stats Banner" block, and selected the first page in the "link" field.
5. Saved the changes.
6. Created a translation for the second page using the Advanced Translation Editor. The "link" field did not appear in the editor, which is expected based on your previous explanation:
"This is why the link field is set to 'Copy' by default and does not appear in the WPML Translation Editor. In this case, it should automatically use the translated URL if the linked page is translated and published."
So I expected the link to the first page to be automatically changed to the French version after translation.
However, after translation, the link still points to the original language version instead of the translated one.
I've made changes to this file:
dev.polarisagency.com/wp-content/plugins/acfml/classes/class-wpml-acf-blocks.php
You can see the changes in the screenshot.
I repeated all the steps by creating two new pages and adding a link from the second page to the first. However, the link still points to the main language.
Hi, I updated the WPML, WPML addons and ACF Pro plugins, created two new pages again, translated them, and the links still point only to the main language.
You can try creating two new pages yourself and following these steps.
If you have doubts about how to set each field, please use the group settings:
- Same fields across languages (for translation with the WPML Translation Editor)
- Different fields across languages (for translation with the WordPress Editor)
Hi, almost all my pages are built using Flexible Content. This is the 'Components Page' field group, as you can see in the screenshot. It seems to be configured correctly. I have properly configured the 'Stats Banner' block, which is a child of Flexible Content. You can check it. hidden link
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Thank you for the details.
I went through half of the group and there are various configuration issues. For example, all the Repeater Fields were set to "Translate". They should be set to "Copy".
Now, this is a huge group and I can not go through it all for you.
If you want to save time, and if all your links ar internal links anyways, then please set the field group to "Same fields across languages" and then translate the page again.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Ths issue is inside your template.
Using the following approach solves the issue while keeping links on "copy".
if ($row === 'stats_banner') {
$image = get_sub_field('image');
$src = wp_get_attachment_image_src($image['id'], 'thumb_2000_0');
echo '<div class="stats-banner" style="background-image: url(' . $src[0] . ');" data-colour="dark">';
echo '<div class="stats-banner__content container">';
echo '<div class="stats-banner__stats">';
echo '<div class="stats-banner__left-stat">';
$largeStat = get_sub_field('large_stat');
if ($largeStat) {
echo '<span>' . $largeStat . '</span>';
}
$text = get_sub_field('text');
if ($text) {
echo $text;
}
echo '</div>';
$colourBox = get_sub_field('colour_box');
$firstColour = $colours[$colourBox['colours']['first']];
$secondColour = $colours[$colourBox['colours']['second']];
// Translate the link and title
$link_url = $colourBox['link']['url'];
$link_title = $colourBox['link']['title'];
if ($link_url && $link_title) {
// Translate the URL (if needed), WPML generally handles URLs of translated pages
$translated_link_url = apply_filters('wpml_permalink', $link_url);
// Translate the link title (if the title is a translatable string)
$translated_link_title = apply_filters('wpml_translate_string', $link_title, 'acf', 'link_title_' . $colourBox['link']['title']);
// Output the translated link
echo '<div class="stats-banner__right-stat" style="background: linear-gradient(to right, ' . $firstColour . ' 40%, ' . $secondColour . ' 40%);">';
if ($colourBox['top_text']) {
echo $colourBox['top_text'];
}
if ($colourBox['stat']) {
echo '<span>' . $colourBox['stat'] . '</span>';
}
if ($colourBox['bottom_text']) {
echo $colourBox['bottom_text'];
}
if ($translated_link_url) {
echo '<a href="' . $translated_link_url . '">' . $translated_link_title . '</a>';
}
echo '</div>';
}
echo '</div>';
echo '</div>';
echo '</div>';
}
Using the 'wpml_permalink' hook in your template will make sure that the correct URL will be loaded for each language.
This will automatically adjust the link without the need to translate it. The downside is, that you will not be able to translate the link text, as it is being copied.
To translate the link text, the link field would need to be set to "Translate" but this would include that you also need to translate the links.
I fixed some of my templates this way:
$translated_link_url = apply_filters('wpml_permalink', $link['url']);
And it actually changes links by adding "fr".
But there's a problem:
I have a page: hidden link
When using apply_filters('wpml_permalink', $link['url']);, it changes the link to hidden link (see screenshot). This link is located on the page: hidden link.
When I click on it, it opens hidden link instead of hidden link.
This happens because the actual translated page URL is hidden link, not hidden link.