Skip Navigation

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

Problem:
The client was experiencing an issue where translated image captions in posts were displaying as {%CAPTION%} instead of the actual translated text, despite being translated in the Advanced Translation Editor (ATE). This issue persisted even after updating themes, plugins, and WordPress itself.

Solution:
We identified that the issue was related to how captions were handled within the theme and WPML. The following steps were recommended:
1. Ensure that all updates are applied for themes, plugins, and WordPress.
2. Check the WPML settings to ensure that the correct custom field translations are enabled.
3. If the issue persists in specific posts, manually add a period at the end of the caption in the original language post, then update the translation.
4. For a more permanent fix, we provided a PHP code snippet to be added to the theme's functions.php file. This code ensures that the caption placeholder is replaced correctly when the post is displayed in a translated version:

// WPML Workaround for compsupp-7497<br />function wpml_compsupp7497_replace_caption_placeholder_shortcode( $output, $attr, $content ) {<br />    $caption_placeholder = '{%CAPTION%}';<br />    if ( strpos( $attr['caption'], $caption_placeholder ) !== false ) {<br />        if ( preg_match( '/attachment_(\d+)/', $attr['id'], $matches ) ) {<br />            $attachment_id = $matches[1];<br />            $translated_attachment_id = apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true );<br />            $actual_caption = get_post_field( 'post_excerpt', $translated_attachment_id );<br />            $attr['caption'] = str_replace( $caption_placeholder, $actual_caption, $attr['caption'] );<br />        }<br />    }<br />    remove_filter( 'img_caption_shortcode', 'wpml_compsupp7497_replace_caption_placeholder_shortcode', 10 );<br />    $output = img_caption_shortcode( $attr, $content );<br />    add_filter( 'img_caption_shortcode', 'wpml_compsupp7497_replace_caption_placeholder_shortcode', 10, 3 );<br />    return $output;<br />}<br />add_filter( 'img_caption_shortcode', 'wpml_compsupp7497_replace_caption_placeholder_shortcode', 10, 3 );

If this solution does not resolve the issue or seems irrelevant due to updates or different configurations, 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 problems persist, 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.

Tagged: ,

This topic contains 18 replies, has 2 voices.

Last updated by martinM-117 1 month, 1 week ago.

Assisted by: Bobby.

Author Posts
August 2, 2024 at 7:18 pm #16034670

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you, I was able to log in using the FTP details and upload the code to the theme's functions.php file.

If you examine the file you can see it at the bottom.

August 2, 2024 at 7:59 pm #16034745

martinM-117

Yes, its now working on all already translated pages and posts.

Thanks alot.

Ill translate a new post tomorrow to check if it works in that setup too and we are finally done :))

August 3, 2024 at 2:35 am #16035009

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you, I will await your confirmation

August 4, 2024 at 7:25 pm #16037115

martinM-117

Now its working as intended, thanks for help 🙂

martinM-117 confirmed that the issue was resolved on 2024-08-04 19:26:47.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.