Allow to upload XML files in WordPress

For security reasons, WordPress does not allow to upload XML files into the media library, by default. To alleviate this limitation, you have to add the following PHP code to functions.php in your current theme.

add_filter('upload_mimes', 'custom_upload_xml');
 
function custom_upload_xml($mimes) {
    $mimes = array_merge($mimes, array('xml' => 'application/xml'));
    return $mimes;
}

In my setup, the path to this file is [WORDPRESS_ROOT]/wp-content/themes/[MY_THEME]/functions.php.

Thanks to Ernie Leseberg for writing about this solution.

Leave a Reply