How to Enable WebP Uploads in WordPress Without a Plugin

Since Apple will finally add support for WebP in Safari 14, I wanted to start using WebP images for my guides and tutorials.

The problem is that WordPress doesn’t support the WebP image format yet. It throws this error when you want to upload one:

Sorry, this file type is not permitted for security reasons.
wordpress webp upload error

As usual, I didn’t want to use a WordPress plugin to fix this issue. I like to have as few plugins as possible.

Luckily, I found a code that worked!

Enable WebP Upload in WordPress Without a Plugin

To enable WebP support in WordPress, you need to add a code snippet into your child theme’s functions.php file.

If you don’t add the snippet in your child theme, it will be gone with the next theme update! Also, download the file as a backup in case something goes wrong.

The path to the file is:


Or, if you don’t have a child theme set up, you could use the Code Snippets plugin.

This is the code:

// Enable WebP in WordPress
add_filter( 'wp_check_filetype_and_ext', 'wpse_file_and_ext_webp', 10, 4 );
function wpse_file_and_ext_webp( $types, $file, $filename, $mimes ) {
    if ( false !== strpos( $filename, '.webp' ) ) {
        $types['ext'] = 'webp';
        $types['type'] = 'image/webp';

    return $types;

add_filter( 'upload_mimes', 'wpse_mime_types_webp' );
function wpse_mime_types_webp( $mimes ) {
    $mimes['webp'] = 'image/webp';

  return $mimes;
enable webp in wordpress code

You can add it at the bottom of the functions.php file.

Save the file, and you should be able to upload WebP images in WordPress!

If you’re trying to upload one in an already-opened post, after adding the code, then refresh the page. Otherwise, you might still get the error.

You might also want to learn how to open and save WebP images in Photoshop, if you’re using it.

That’s a Wrap

I hope you found the post useful, and you managed to enable WebP uploads in WordPress!

If you have questions or thoughts, please leave a comment or send me a message using the contact page.

Leave a Comment