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;
}
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.
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).
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.
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.
"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.
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;
}