Skip to content Skip to sidebar

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

Problem:
The client is unable to display SVG images on the translated pages even after following the instructions from the WPML documentation.
Solution:
We have confirmed that the workaround provided has been added to the functions.php file of the client's theme. Here is the code that should be used:

// WPML Workaround for compsupp-6933<br />
add_filter('wp_get_attachment_metadata', 'wpml_compsupp6933_fix_attachment_metadata_file_path', 10, 2);
function wpml_compsupp6933_fix_attachment_metadata_file_path($data, $attachment_id) {    

// Only apply the workaround if WPML Media and SVG Support plugins are active    
if( class_exists('WPML_Media') && function_exists('bodhi_svgs_generate_svg_attachment_metadata') ) {
if (isset($data['file']) && !preg_match('/\d{4}\/\d{2}\//', $data['file'])) {            

// Get the upload directory info           
$upload_dir_info = wp_upload_dir();            

// Extract the year and month from the basedir            
$year_month = date('Y/m', strtotime(get_post_field('post_date', $attachment_id)));           

// Prepend the year and month to the file            
$data['file'] = $year_month . '/' . $data['file'];        
}    
}    
return $data;
}

Please ensure that there are no errors within the file that could prevent the snippet from being saved. You can find the errata for this issue here: https://wpml.org/errata/svg-support-activating-wpml-media-strips-uploads-folders-from-svg-image-url/. If you have followed these steps and are still experiencing issues, we recommend that you open a new support ticket. You can do so by visiting the WPML support forum.

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 8 replies, has 2 voices.

Last updated by stelS 1 year, 10 months ago.

Assisted by: Andreas W..

Author Posts
November 29, 2023 at 1:00 pm #14951331

stelS

Tell us what you are trying to do?

Is there any documentation that you are following?

Hello,

After following the instructions on this page (which you indicated to me via chat) https://wpml.org/errata/svg-support-activating-wpml-media-strips-uploads-folders-from-svg-image-url/. I can't get the SVG images to appear on the translated pages after inserting them again and translating the pages again.

What is the link to your site?

November 30, 2023 at 3:05 am #14957309

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Take note, that this snippet might not work when using a plugin like Code Snippets or other similar plugins.

Did you try to upload the images again, after adding the snippet to the functions.php file of your Child Theme?

In this case, if the original SVG file is missing, upload it again to the media library or directly on the content, then translate the content.

If you use a different image in a second language, this SVG file might need to get uploaded again on WPML > Media Translation.

Also, if this will still not solve the issue, please clear the WP Rocket Cache in all languages (admin bar) and also try clearing the Redis Object Cache.

In case that this will not solve the issue, please let me know.

Best regards
Andreas

November 30, 2023 at 9:36 am #14960279

stelS

Please, can you delete my links to our staging website in OP.

Flow:
1.- I added snippet to our Child Theme's functions.php
2.- Uploaded again SVG images to main images
3.- Uploaded translated SVG images to Media Translation
4.- Cleared cache.

Still not working.

FYI: As you can see, there are stars-rating's SVG images that are actually working (orange ones) and others stars-rating's SVG images that are not working (Google Play and white stars).

November 30, 2023 at 2:38 pm #14964021

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

I would like to offer to have a closer look at the problem and request temporary access (wp-admin and FTP) to the website to investigate this issue further.

You can find the required fields below the comment section when you log in to leave the next reply. The information you provide is private, which means only you and I can see and access it.

IMPORTANT
Please be sure to make a backup copy of the website and database before allowing us access.
If you can't see the wp-admin / FTP fields, your post and website credentials are set as PUBLIC. DO NOT publish the data unless you see the required wp-admin / FTP fields.

I may have to install a plugin called "All In One WP Migration" to make a copy of the website where I can investigate the issue further.

However, I would also be very grateful if you could provide a staging site or copy of the website from your server yourself for this purpose.

If you have any questions about creating such a staging site, you can consult your hosting provider. Just take note that WPML should be registered on this site again.

If you are unable to provide such a copy of the site for testing, please let me know on this ticket.

The private response form looks like this:
hidden link

Next time you reply, click "I still need assistance."

Video:
hidden link

Please note that we are obliged to request this information individually on each ticket. We may not access any access information not specifically submitted on this ticket in the private response form.

Best regards
Andreas

December 1, 2023 at 6:00 am #14968819

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for the access.

It would be very helpful if you could name me an exact example of content and media, as I have been searching for some minutes now, and did not find a page that uses an SVG that needs to be replaced. The only one I found so far is not yet translated to 100%.

Also, take note that I found the image source URLs when translating the page by searching for "http" on the Advanced Translation Editor, which means that you might need to translate those source URLs.

Guide:
https://wpml.org/documentation/translating-your-contents/advanced-translation-editor/#main-features-of-the-advanced-translation-editor

Best regards
Andreas

December 4, 2023 at 11:18 am #14985757

stelS

In our homepage in Spanish, you can check this section:
hidden link

English:
hidden link

Probably, what you found not being translated to 100% was because I made some minimal changes in design. But right now home is 100% translated.

December 4, 2023 at 11:39 am #14986077

stelS

"Also, take note that I found the image source URLs when translating the page by searching for "http" on the Advanced Translation Editor, which means that you might need to translate those source URLs."

I don't know what do you mean. I don't find any HTTP on the Advanced Translation Editor. All media are translated in WPML > Media Translation. Every other PNG and JPG are shown correctly.

Neither did I find any HTTP in our source code. All i can see is this problem stated here: https://wpml.org/errata/svg-support-activating-wpml-media-strips-uploads-folders-from-svg-image-url/

"With WPML Media Translation activated: hidden link"

Regards
Ismael

December 5, 2023 at 2:07 pm #14998721

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello Ismael,

At the moment I can confirm that the provided workaround is added to the functions.php file of your theme:

// WPML Workaround for compsupp-6933
add_filter('wp_get_attachment_metadata', 'wpml_compsupp6933_fix_attachment_metadata_file_path', 10, 2);
 
function wpml_compsupp6933_fix_attachment_metadata_file_path($data, $attachment_id) {
 
    // Only apply the workaround if WPML Media and SVG Support plugins are active
    if( class_exists('WPML_Media') && function_exists('bodhi_svgs_generate_svg_attachment_metadata') ) {
         
        if (isset($data['file']) && !preg_match('/\d{4}\/\d{2}\//', $data['file'])) {
            // Get the upload directory info
            $upload_dir_info = wp_upload_dir();
     
            // Extract the year and month from the basedir
            $year_month = date('Y/m', strtotime(get_post_field('post_date', $attachment_id)));
     
            // Prepend the year and month to the file
            $data['file'] = $year_month . '/' . $data['file'];
             
        }
    }    
 
    return $data;
}

Source: https://wpml.org/errata/svg-support-activating-wpml-media-strips-uploads-folders-from-svg-image-url/

Further, it seems there is an error inside the file, which for I can not save the snippet.

Best regards
Andreas

December 18, 2023 at 10:58 am #15082633

stelS

Hello Andreas, we added that snippet to functions.php and right now it is working.

Thanks!

Kind regards!