Skip to content Skip to sidebar

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

Problem:
If you're experiencing issues where the translated captions in an image slider are not displayed and instead show the default language captions, even though they are translated in the translation editor.
Solution:
First, ensure that you have the latest versions of Elementor and JetElements plugins installed. Next, you need to add custom PHP code to your theme's functions.php file to handle the translation of image captions in sliders. Here is the code you should insert:

function translate_gallery($metadata, $object_id, $meta_key, $single){
    $meta_needed = 'gallery';
    if ( isset( $meta_key ) && $meta_needed == $meta_key ){
        remove_filter( 'get_post_metadata', 'translate_gallery', 100 );
        $current_meta = get_post_meta( $object_id, $meta_needed, TRUE );
        $to_translate = explode( ',', $current_meta );
        foreach ( $to_translate as $key => $value ){
            $to_translate[$key] = apply_filters( 'wpml_object_id', $value, 'attachment', true );
        }
        add_filter('get_post_metadata', 'translate_gallery', 100, 4);
        $current_meta = implode( ',', $to_translate );
        return $current_meta;
    }
    return $metadata;
}
 
add_filter( 'get_post_metadata', 'translate_gallery', 100, 4 );

Additionally, modify the Jet Engine plugin's code to ensure compatibility with WPML. In the file \wp-content\plugins\jet-engine\includes\classes\tools.php, after line 792, add the following code:

if ( is_numeric( $img_data ) ) {
                    $id = $img_data;
                } elseif ( is_array( $img_data ) && isset( $img_data['id'] ) && isset( $img_data['url'] ) ) {
                    $id = $img_data['id'];
                } else {
                    $id = attachment_url_to_postid( $img_data );
                }

Add the following

// WPML Workaround for wpmlsupp-12960 
                if ( class_exists('Sitepress') ) { 
                    $current_lang = apply_filters( 'wpml_current_language', NULL ); 
                    $id = apply_filters( 'wpml_object_id', $id, 'attachment', TRUE, $current_lang ); 
                }

If this solution does not resolve your issue or becomes irrelevant due to updates, we 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 the problem persists, please open a new support ticket at WPML support forum for further assistance.

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

Last updated by Kor 1 month, 1 week ago.

Assisted by: Kor.

Author Posts
July 4, 2025 at 3:46 pm #17202551

mickS-3

I found another problem: when the images are in a slider the translated caption is not displayed but the default language. Example: hidden link

July 7, 2025 at 9:34 am #17207493

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply. I'm on this page hidden link and I'm still not so clear which slider you are referring to. Could you please highlight is using a screenshot?

July 7, 2025 at 10:50 am #17207879

mickS-3

The image slider with captions. Please check: hidden link

The caption is translated in the translation editor but not visible on page.

July 7, 2025 at 5:15 pm #17210558

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply. I can see the issue now. It looks like the issue only happens with the image caption in the slider.

Could you replicate the issue on our sandbox site here hidden link so that I could check and escalate this for you?

You can install the required plugins or theme to replicate it.

July 8, 2025 at 3:02 pm #17214884

mickS-3

Done and replicated the issue. Please check: hidden link

July 8, 2025 at 3:29 pm #17215165

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for replicating the issue on our sandbox site. I will share this with our 2nd Tier Support for further investigation.

July 11, 2025 at 6:05 pm #17229182

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your patience. We have a workaround for this and could you please backup and insert the custom PHP code below into your theme's functions.php file?
Then, recheck to see if the translated page is showing the correct translated image titles and captions.

function translate_gallery($metadata, $object_id, $meta_key, $single){
	$meta_needed = 'gallery';
	if ( isset( $meta_key ) && $meta_needed == $meta_key ){
		remove_filter( 'get_post_metadata', 'translate_gallery', 100 );
		$current_meta = get_post_meta( $object_id, $meta_needed, TRUE );
		$to_translate = explode( ',', $current_meta );
		foreach ( $to_translate as $key => $value ){
			$to_translate[$key] = apply_filters( 'wpml_object_id', $value, 'attachment', true );
		}
		add_filter('get_post_metadata', 'translate_gallery', 100, 4);
		$current_meta = implode( ',', $to_translate );
		return $current_meta;
	}
	return $metadata;
}

add_filter( 'get_post_metadata', 'translate_gallery', 100, 4 );
July 14, 2025 at 7:32 am #17231860

mickS-3

Hi Kor,

I've added the snippet using the WPCode plugin: hidden link

Unfortunately, this didn't resolve the issue. I've cleared all caches and also tried re-saving the translation, but the problem persists.

Would it be possible for you to make my next comment private so I can securely share access to the website for you to take a closer look?

July 14, 2025 at 7:51 am #17231919

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply. I will require temporary access (WP-Admin and FTP) to a test site where the problem has been replicated, if possible. This will enable me to provide better assistance and determine if any configurations need to be modified.

Please note that it is important to have a backup for security purposes and to prevent any potential data loss. You can use the UpdraftPlus plugin (https://wordpress.org/plugins/updraftplus/) to fulfill your backup requirements.

Your upcoming reply will be treated with confidentiality and will only be visible to you and me.

✙ To resolve the issue, I may need your consent to deactivate and reactivate plugins and the theme, as well as make configuration changes on the site if necessary. This emphasizes the significance of having a backup.

July 14, 2025 at 3:33 pm #17234810

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply. Please backup and update the Elementor and JetElements plugins to the latest version.

Then, in \wp-content\plugins\jet-engine\includes\classes\gallery.php they're calling this method Jet_Engine_Tools::get_attachment_image_data_array

Open the file ......\wp-content\plugins\jet-engine\includes\classes\tools.php

Look for line 792

Right after:

if ( is_numeric( $img_data ) ) {
					$id = $img_data;
				} elseif ( is_array( $img_data ) && isset( $img_data['id'] ) && isset( $img_data['url'] ) ) {
					$id = $img_data['id'];
				} else {
					$id = attachment_url_to_postid( $img_data );
				}

Add the following:

// WPML Workaround for wpmlsupp-12960 
				if ( class_exists('Sitepress') ) { 
					$current_lang = apply_filters( 'wpml_current_language', NULL ); 
					$id = apply_filters( 'wpml_object_id', $id, 'attachment', TRUE, $current_lang ); 
				}

If you're not sure how to edit the code, please share FTP access here, and I will edit it for you.

July 18, 2025 at 10:19 am #17249512

mickS-3

This fixed the issue. Thanks!

Will the fix be implemented in the next Jet Engine update since the code will be removed when updating the plugin?

July 18, 2025 at 10:21 am #17249515

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply. We've contacted the plugin author, but we are not sure when they will release an update for this.

July 18, 2025 at 10:24 am #17249519

mickS-3

Okay... How do I implement the fix in a durable way then? I don't want to add the code each time I update Jet Engine. According to this page it's 100% compatible: https://wpml.org/plugin/jetengine/

Guess they implement it anyway right?

July 18, 2025 at 10:27 am #17249539

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thank you for your reply. The plugin was last tested on June 20, 2024. We’ve already shared the solution with the plugin developers, and while we expect them to implement it, we cannot guarantee it as the plugin is maintained by a third party.