WPML
ステータス
未解決
報告対象
WPML Media Translation 2.7.0
関連するプラグイン/テーマ
SVG Support
トピックタグ
Compatibility

問題の概要

SVG Supportプラグインを使用している場合、WPML Media Translationプラグインが有効になっていると、SVG画像のURLが不完全になります。例:

  • WPML Media Translationが有効な場合: https://domain.com/wp-content/uploads/logo.svg
  • WPML Media Translationが無効な場合: https://domain.com/wp-content/uploads/2022/05/logo.svg

回避策

  • テーマのfunctions.phpファイルに以下のスニペットを追加します。
    // 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;
    }

すべての既知の問題 →