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: ATE, Compatibility
This topic contains 18 replies, has 2 voices.
Last updated by martinM-117 3 months, 1 week ago.
Assisted by: Bobby.
Author | Posts |
---|---|
July 15, 2024 at 8:00 pm #15956491 | |
martinM-117 |
Background of the issue: Symptoms: Questions: |
July 15, 2024 at 10:53 pm #15957045 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
I would like to request temporary access (wp-admin and FTP) to your site to test the issue. **Before we proceed It is necessary to take FULL BACKUP of your database and your website. Providing us with access, you agree that a backup has been taken ** I often use the Duplicator plugin for this purpose: http://wordpress.org/plugins/duplicator/ NOTE: If access to the live site is not possible and the staging site does not exist please provide me with a duplicator package created with the duplicator plugin. Thank you, |
July 16, 2024 at 11:06 pm #15962964 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Thank you for the access details! I was able to reproduce the issue with a new page. It looks like the content within the [caption] shortcode is not parsed correctly even though its being translated in the ATE editor. We are currently investigating this, in the meantime you can use the following workaround: 1. Go to the page and edit 2. Use the language switcher at the top header and switch to the translation (dismiss the warning ) 3. Manually edit the caption 4. update Loom video showing the workaround: |
July 16, 2024 at 11:25 pm #15962977 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi, Please go to Appearance-> Themes-> and update your theme and its add-ons to their latest versions. The current theme is on Version: 27.4.1 On Version 27.4.2 – May 7th, 2024 the theme developers also released a fix that should resolve this issue. *BeBuilder - Image element - Caption field - Dynamic data added Let me know your results, please. |
July 17, 2024 at 8:51 pm #15968444 | |
martinM-117 |
Hi Bobby, I updated theme to newest version 27.5.2.1, then all plugins Im curently using and in the end WP to version 6.6. But the problem still persist even on test page you created. I tried again to edit the translation on "Mount Ainos" post and reenter caption translate in ATE and saved but nothing changed.. Isnt there problem, that the right "custom field translation" isnt checked in settings and this "caption" isnt right setting ? That your workaround is indeed clever, but we have thousands of photos on the page and still growing, that is insane job to do for every 1 caption... That sadly beats the whole purpose of ATE and WPML 🙂 Should I ask BeTheme support team to look into it, or are you in contact with them? Maybe that could help too. Thanks for your time |
July 18, 2024 at 6:42 pm #15974266 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi Martin, I will discuss this with our compatibility team to further investigate. Still, yes I would recommend also opening a ticket with their support if you can to help expedite the issue. I agree, the workaround is simply a workaround and not meant as a permanent solution 🙂 I will update you as soon as I have new information here. |
July 22, 2024 at 7:15 pm #15988853 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi, i am still working on this and will update you once there are news |
July 22, 2024 at 11:47 pm #15989620 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi Martin, I have run a few tests and it can confirm that with the standard WP editor this works as expected with WPML. The issue does seem to stem from the issue that was fixed from the theme. However, now that you have updated the version I do see that it is working OK for me. See the new WPML Test 2 page I created --> hidden link I do not know why the 'caption' in the ATE editor still references the old caption, however, the correct caption is listed under this item which is correctly registered field-mfn-page-items-0-0-wraps-0-items-0-attr-content |
July 23, 2024 at 6:49 pm #15994102 | |
martinM-117 |
Hi Bobby, I understand now, still little confusing, but I do know what to do now. Look in ATE for this page in particular, its same for all others I had done: there are no such field in ATE to translate. Can you please check my settings if there are some custom field selection not selected correctly ? Also I got answer from BeTheme support : It seems that WPML uses the function wp_content but not the do_shortcode function. Please contact WPML support if there is any option to change that, or you can translate this manually by editing a page. so it seems there are some minor issues between WMPL and BeTheme plugins that need to fix anyway. |
July 23, 2024 at 7:13 pm #15994192 | |
martinM-117 |
Edit: I just find that this field is visible and transtaled in "pages" and working properly but not on "posts" where the field is missing |
July 23, 2024 at 11:16 pm #15995077 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Thank you for updating me! A few things to note: 1. If you go to posts and attempt to add a new translation to any of your posts it will work OK and the captions will translate as expected. 2. In a brand-new installation with the latest version of the theme and WPML I am not able to reproduce the issue With #1 and #2 we can say that this is working as expected with the latest version of the theme. 3. The issue remains in posts such as Mount Ainos, try the following to resolve: - Edit the post The Caption displays OK now. See here the first Caption that I tested these steps with. |
July 24, 2024 at 9:16 pm #16000512 | |
martinM-117 |
Hello, I do have good and bad news: point 3) is working and I can repair older posts. point 1) and 2) is not working properly. I just did a new translation of this post: hidden link and 2nd try: hidden link and its again %CAPTION%, so no it doesnt work at all and I need to manually do step 3) for old and new translations altogether. Or do you mean no new translations, but new posts created in "original" language ? so all our 106 posts we already have published in original language will not work automatically and we need to add "," to every single photo and then translate? |
July 26, 2024 at 6:51 am #16006951 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Thank you for updating me! We are reviewing this and will update you as soon as I have some news. |
July 30, 2024 at 6:11 pm #16021844 | |
Bobby Supporter
Languages: English (English ) Timezone: America/Los_Angeles (GMT-08:00) |
Hi there, Please add the following code to your functions.php file: // WPML Workaround for compsupp-7497 function wpml_compsupp7497_replace_caption_placeholder_shortcode( $output, $attr, $content ) { // Define the placeholder constant $caption_placeholder = '{%CAPTION%}'; // Check if the caption attribute contains the placeholder if ( strpos( $attr['caption'], $caption_placeholder ) !== false ) { // Extract the attachment ID from the shortcode attributes if ( preg_match( '/attachment_(\d+)/', $attr['id'], $matches ) ) { $attachment_id = $matches[1]; // Translate the attachment ID to the current language $translated_attachment_id = apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true ); // Retrieve the actual caption from the translated attachment's post_excerpt $actual_caption = get_post_field( 'post_excerpt', $translated_attachment_id ); // Replace the placeholder with the actual caption in the caption attribute $attr['caption'] = str_replace( $caption_placeholder, $actual_caption, $attr['caption'] ); } } // Remove the filter to prevent recursive calls remove_filter( 'img_caption_shortcode', 'wpml_compsupp7497_replace_caption_placeholder_shortcode', 10 ); // Return the modified caption shortcode output $output = img_caption_shortcode( $attr, $content ); // Add the filter again add_filter( 'img_caption_shortcode', 'wpml_compsupp7497_replace_caption_placeholder_shortcode', 10, 3 ); return $output; } add_filter( 'img_caption_shortcode', 'wpml_compsupp7497_replace_caption_placeholder_shortcode', 10, 3 ); If you are not confident making adding this to functions.php, I'd be happy to do it, for please review the FTP access as the one I have is not currently working.(you can edit the previous private reply if needed) NOTE: Always have a recent and working backup before making any changes recommended by our team or a 3rd party Let me know your results, please. |
August 2, 2024 at 5:23 pm #16034446 | |
martinM-117 |
Hello, I do want you to put the php code inside, I dont want to break the stuff as Im not a programmer. I checked again the FTP login and it should work ok. GEO and IP security is turned off so you should be able to login in normaly |