Zum Inhalt springen Zur Seitenleiste springen

Open

Reported for: WPML Media Translation 2.7.0

Topic Tags: Compatibility

Overview of the issue

If you are using the SVG Support plugin, you will notice that when the WPML Media Translation plugin is active, the SVG image URL is incomplete. For example:

  • With WPML Media Translation activated: https://domain.com/wp-content/uploads/logo.svg
  • Without WPML Media Translation activated: https://domain.com/wp-content/uploads/2022/05/logo.svg

Workaround

  • Add the following snippet to your functions.php theme file:
    // 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;
    }
    

6 Antworten zu “SVG Support - Activating WPML Media strips uploads folders from SVG image url”

  1. this did not work for me but made things worse and interfered with existing images.
    Had to recover page from a backup and replace svgs with pngs.

    Use with caution only on staging!!!

    • Hi Stefan,
      Thanks for reaching out, and sorry to hear about the trouble you experienced.

      We created this pull request two months ago, which might help. If possible, could you try it on a staging copy and let us know how it works for you? Your feedback would be greatly appreciated!

Hinterlasse eine Antwort

Bitte bleibe beim Thema und sei respektvoll zu anderen. Wenn du Hilfe bei Problemen benötigst, die nicht mit diesem Beitrag zusammenhängen, nutze unser Support-Forum, um einen Chat zu starten oder ein Ticket einzureichen.

Du kannst diese Tags verwenden:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>