Created
February 10, 2026 14:07
-
-
Save hmowais/67ddb4da5f8c072bc9d3e4a45ac8525e to your computer and use it in GitHub Desktop.
SVG Support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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