How To Enable Webp Uploads In WordPress

Home » Blog » WordPress Development » How To Enable Webp Uploads In WordPress

Webp is a modern image format that can help you speed up your WordPress website. It can be compressed to save space, and make your website’s size smaller. Other formats such as PNG and JPEG can also be compressed but they can’t be compressed as much as Webp without them losing quality.

Even Google recommends Webp images over other formats in their Pagespeed Insights tool.

By default, WordPress doesn’t allow uploading Webp images for security reasons. But there are two easy ways to enable Webp image uploads:

Method 1: Enable Webp Uploads Using This PHP Code Snippet

If you want to enable Webp uploads, all you have to do is place this code at the end of your theme’s functions.php file:

/*
 * Enable Webp Uploads
 */
function wpturbo_enable_webp_uploads($mimes) {
  $mimes['webp'] = 'image/webp';
  return $mimes;
}
add_filter('upload_mimes', 'wpturbo_enable_webp_uploads');

The above code hooks into the ‘upload_mimes’ filter and then adds ‘image/webp’ mime-type to the array of accepted mime-types. This is all you need to do to enable Webp uploads in WordPress.

To edit your theme’s functions.php file, you can log into your website’s FTP service and edit the file from there.

You can also add this code as a site-specific, standalone plugin to your website. We recommend this because it will make sure that your website allows Webp uploads even if you switch themes.

Use our Plugin Header generator to generate a plugin file, then add this code to it.

Method 2: Use a Plugin

If for some reason you don’t want to use the above PHP code, you can install the free Webp Express plugin to enable Webp image support on your website. It also comes with some additional features related to the Webp format like conversion from other image formats.

Conclusion

If you want to speed up your WordPress website, you’ll want to use modern image formats such as SVG and Webp. Modern image formats are much smaller in size than their counterparts because they use the latest compression algorithms. If your website is image-heavy, Webp image format can improve your website’s speed by a lot.

If you want to enable SVG file uploads, read our tutorial on how to enable SVG file uploads in WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *

Register an account to save your snippets or go Pro to get more features.