Categories
WordPress

Adding a Mime Type to WordPress

WordPress doesn’t have .xml as part of its default mime-types, so we need to add it ourselves. How can you do that?

Search for wp_get_mime_types() function in the WordPress core files. You will find it inside the wp-includes/function.php. In the function, you will find a filter called mime_types.

We have an appropriate filter now, and we just need to hook it up and add our new mime type to the existing mime type array. I’ve added .xml to this example, but if you need to add another mime type, just replace the values with your own.

Add the following to your functions.php:

Please Note:

Do not replace the entire mime type array, you just have to add the above code to it.
Refresh your website and see the mime-type array (which is really long) with the new mime-type added.
And, to test that everything worked as expected, upload your XML file, which should now be uploaded perfectly.