Background of the issue:
I am trying to use Elementor Loop 'Alternate Template' to display translations on my website. The issue can be seen on this page: hidden link
Symptoms:
Elementor Loop 'Alternate Template' is not using the translation and is showing German instead of the expected English/Czech translation.
Questions:
Why is the Elementor Loop 'Alternate Template' not displaying the correct translation?
How can I ensure the Elementor Loop 'Alternate Template' shows the English/Czech translation instead of German?
Thank you for the updates, I can see the problem. I've also checked in very much detail as well as some workaround taken from an existing report. But none of this seems to work so far.
However, I need more time on this to check a few other solutions. I'll get back to you on Monday.
- Add the following code in your current theme's functions.php file:
// WPML Workaround for compsupp-6865
add_filter('elementor/frontend/before_render', 'wpml_compsupp6865_filter_loop_grid_widget');
function wpml_compsupp6865_filter_loop_grid_widget($element) {
if ('loop-grid' !== $element->get_name()) {
return $element;
}
$settings = $element->get_settings();
if (!isset($settings['alternate_templates']) || !is_array($settings['alternate_templates'])) {
return $element;
}
$alternate_settings = $settings['alternate_templates'];
foreach ($alternate_settings as $key => $value) {
if (empty($value['template_id']) || !is_numeric($value['template_id'])) {
continue;
}
// Use apply_filters to adjust template_id for WPML
$id = apply_filters('wpml_object_id', $value['template_id'], get_post_type($value['template_id']), true);
if (!is_numeric($id)) {
continue;
}
// Update the template_id in alternate_settings
$alternate_settings[$key]['template_id'] = $id;
}
// Update the settings with the modified alternate_templates
$settings['alternate_templates'] = $alternate_settings;
$element->set_settings('alternate_templates', $settings['alternate_templates']);
}
- Save the file.
- Clear all caches and recheck.
I've applied this code in your staging site's Hello Elementor Child theme's functions.php file and it solved the problem. Please check at hidden link and hidden link.
When you apply this on your live site, please remember to take full backup of your site and database beforehand.