Skip to main content
Login Join
Snippet · PHP

Allow SVG, JSON & DOC File Uploads in WordPress

Shared by Sumit Javia | Senior WordPress Developer · May 9, 2026 · @upload_mimes

27 views
Back to Snippets

This snippet extends WordPress upload support by allowing additional file types such as SVG, SVGZ, JSON, and DOC files through the Media Library. It also demonstrates how to remove unwanted mime types (like EXE) for improved security. Useful for developers working with custom assets, animations, or document uploads.

/* SVG Mimes */
function sj_addFileTypesToUploads($file_types) {
    // New allowed mime types.
    $new_filetypes = array(
        'svg'  => 'image/svg+xml',
        'svgz' => 'image/svg+xml',
        'json' => 'text/plain',
        'doc'  => 'application/msword',
    );

    // Merge the existing and new mime types
    $file_types = array_merge($file_types, $new_filetypes);

    // Optional: Remove a mime type
    unset($file_types['exe']);

    return $file_types;
}
add_filter('upload_mimes', 'sj_addFileTypesToUploads');

/* JSON file allowed code */
add_filter(
	'upload_mimes',
	function( $types ) {
		return array_merge( $types, [ 'json' => 'text/plain' ] );
	}
);
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments