允许上传svg

function wps_enable_svg_upload($mimes)
{
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter('upload_mimes', 'wps_enable_svg_upload');

/**
 * Fix SVG display in WordPress Media Library
 */
function wps_fix_svg_thumb_display()
{
    echo '<style>
		td.media-icon img[src$=".svg"], img[src$=".svg"].attachment-post-thumbnail {
			width: 100% !important;
			height: auto !important;
		}
	</style>';
}
add_action('admin_head', 'wps_fix_svg_thumb_display');

/**
 * Fix SVG display in the media library and bypass security checks that might block them.
 */
function mjagency_fix_svg_upload($data, $file, $filename, $mimes)
{
	$ext = isset($data['ext']) ? $data['ext'] : '';
	if (empty($ext)) {
		$exploded = explode('.', $filename);
		$ext = strtolower(end($exploded));
	}

	if ($ext === 'svg') {
		$data['type'] = 'image/svg+xml';
		$data['ext'] = 'svg';
	}
	return $data;
}
add_filter('wp_check_filetype_and_ext', 'mjagency_fix_svg_upload', 10, 4);

/**
 * Ensures SVG images are visible in the WordPress admin/media library.
 */
function mjagency_admin_svg_css()
{
	echo '<style>
		.attachment-266x266, .thumbnail img[src$=".svg"] { 
		width: 100% !important; 
		height: auto !important; 
		}
	</style>';
}
add_action('admin_head', 'mjagency_admin_svg_css');
×
允许上传svg

允许上传svg

function wps_enable_...