Skip to content

Instantly share code, notes, and snippets.

@hmowais
Created February 10, 2026 14:07
Show Gist options
  • Select an option

  • Save hmowais/67ddb4da5f8c072bc9d3e4a45ac8525e to your computer and use it in GitHub Desktop.

Select an option

Save hmowais/67ddb4da5f8c072bc9d3e4a45ac8525e to your computer and use it in GitHub Desktop.
SVG Support
// Allow SVG uploads
function custom_add_svg_support($mimes) {
// Add SVG to allowed mime types
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'custom_add_svg_support');
// Optional: Sanitize SVG files for security
function custom_check_svg($file) {
if ($file['type'] === 'image/svg+xml') {
$svg = simplexml_load_file($file['tmp_name']);
if ($svg === false) {
$file['error'] = 'Invalid SVG file.';
}
}
return $file;
}
add_filter('wp_handle_upload_prefilter', 'custom_check_svg');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment