I have an old school user who wants to upload an excel file to our Wordpress page.

Basically, Wordpress does not allow this.



I put the following into functions.php before the end "Includes":

function my_custom_mime_types( $mimes ) {

    // New allowed mime types.
    $mimes['xls'] = 'application/vnd.ms-excel';

    return $mimes;
add_filter( 'upload_mimes', 'my_custom_mime_types', 9999 );

But upon uploading an .xls file I get an error message that due to security this is not allowed (re-translated from my native language).

Was this an attempt in the right direction? How can I make this work?


3 Answers 3


I think the proper filter would be mime_types found here.

function wpse294198_mime_types( $mimes ) {
    $mimes['xls|xlsx'] = 'application/vnd.ms-excel';
    return $mimes;
add_filter( 'mime_types', 'wpse294198_mime_types' );

You can use command line tool file (linux|macOS) to see the mime type, e.g. file --mime-type -b somefile.xls

  • 1
    add_filters ruined the theme and nothing appeared on the screen. using add_filter (without ending s) didn't do this, but I still cannot upload xls files, it says for security reasons it does not allow uploading it
    – Gergely
    Feb 28, 2018 at 13:12

I tried the above solution but didn't work for me in the end

I allowed all the mime types via wp-config.php


You can create your custom restriction when the file is submitted. use $_FILES array and put your restriction on the extension of the file and type before upload.

  • Allowing everything is not recommended unless you don't care about security.
    – Sjeiti
    Dec 13, 2021 at 21:03

The upload_mimes hook is correct, the mime-type is not (anymore?).

The following is working for WP 5.8.2

function my_upload_mimes( $mimes ) {
        return array_merge($mimes, array (
            'xls' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'csv' => 'text/csv'
add_filter( 'upload_mimes', 'my_upload_mimes' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.