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.
This topic contains 18 replies, has 2 voices.
Last updated by 3 months, 1 week ago.
Assisted by: Bobby.