WPML translation of images caption doesnt work

Hello there,

I tried 1st to reach up to the WMPL support team, but they do not know how to resolve the issue so far, so they suggest to ask you too.

This bug should be updated by BeTheme version:

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


But I have theme updated to newest version, WP to 6.6 and all plugins up to date, but the visual bug still persists.

The problem is that, after translating captions of images using WPML ATE, it shows in ATE that it translated, but on front end, it shows instead {%CAPTION%}


example of page where you can see it:

or test page made by WMPL support:


Any help would be very much appreciated.


Thanks

Regard

Martin

Comments

  • Hey,

    Please send us the WordPress dashboard and FTP access privately through the contact form, which is on the right side at https://themeforest.net/user/muffingroup#contact and we will check what might be the reason.

    Notice!

    Please attach a link to this forum discussion.

    Sending incorrect or incomplete data will result in a longer response time.

    Therefore, please ensure that the data you send are complete and correct.

    Thanks

  • Sent :)

  • Are there any particular steps to resolve this issue?

    I have copied an image from the WPML page to a new testing page, translated this page, and it worked correctly. See this link: https://www.crazyfamilyontheroad.com/en/mfn-test-page-en/


    Best regards

  • Hello,

    I'm sorry but it's not working properly. As you can see on a test page, you created, there are no %CAPTION% errors, but the image displays not the caption but another dynamic attribute.

    "This is test EN" is not caption field in WPML ATE

    As you can see on the original mount ainos page

    ïn original language, caption is just right:

    So I think there is some problem with the proper align of the dynamic field and its name between WPML and BeTheme.


    About the particular steps of translating. I do it by the basic guide from WPML.

    So I open ATE for a post I need to translate, then translate all the fields, then click complete and save, and then check on the front end to see if it's all correct. That %CAPTION% is now on every one post I translate...just 2 days ago I did the translation for this post and it was same again :(

    https://www.crazyfamilyontheroad.com/en/agio-gerasimos-monastery/


    Regards

    Martin

  • 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.


    Best regards

  • Thanks for your help, I reached to them so they can look into in, because I found that on "pages" i do have this field in ATE:

    field-mfn-page-items-0-0-wraps-0-items-0-attr-content

    which can be translated and is correct on front end, but on "posts" this field in ATE is missing.

  • Please update us if you receive any information regarding this.


    Best regards

  • Hello,

    After many days and tries and errors, support WPML finally make it work:

    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)


    ------

    After this, they added the code inside the file and now its working. Hope this update help you too :)


    Regards

    Martin

  • Thanks for the update!

Sign In or Register to comment.