{"id":89283,"date":"2021-06-07T20:22:05","date_gmt":"2021-06-07T20:22:05","guid":{"rendered":"https:\/\/make.wordpress.org\/core\/?p=89283"},"modified":"2021-11-09T14:35:40","modified_gmt":"2021-11-09T14:35:40","slug":"wordpress-5-8-adds-webp-support","status":"publish","type":"post","link":"https:\/\/make.wordpress.org\/core\/2021\/06\/07\/wordpress-5-8-adds-webp-support\/","title":{"rendered":"WordPress 5.8 adds WebP support"},"content":{"rendered":"<p class=\"wp-block-paragraph\"><a href=\"https:\/\/developers.google.com\/speed\/webp\">WebP<\/a> is a modern image format that provides improved lossless and lossy compression for images on the web. WebP images are around 30% smaller on average than their JPEG or PNG equivalents, resulting in sites that are faster and use less bandwidth. WebP is supported in all modern browsers <a href=\"https:\/\/caniuse.com\/webp\">according to caniuse<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From WordPress version 5.8 forward, you can upload and use WebP images in WordPress like you would a JPEG or PNG image today (as long as your hosting service supports WebP). Switching to the WebP format for your images will improve your site\u2019s performance and your site visitor\u2019s experience.\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How WebP Helps You<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WebP images are significantly smaller than their JPEG equivalents, so visitors to your site will see the complete page loaded more quickly. Smaller images take less bandwidth to transmit, and your images still get all of the responsive benefits of <code>srcset<\/code> and lazy loading by default. Finally, WebP is supported in all major browsers, so most sites can start using them today.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating WebP images<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Image editing tools support exporting in WebP, or you can also use command line <a href=\"https:\/\/developers.google.com\/speed\/webp\/docs\/precompiled\">conversion tools<\/a> or web based tools like <a href=\"https:\/\/squoosh.app\">Squoosh<\/a>. Once you save your images as WebP, upload them to WordPress and use them like you would any other image.\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using WebP images<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WebP images work like any other image in WordPress with some small caveats.\u00a0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WebP images support lossy and lossless compression, as well as an animated format and support for transparent images. In WordPress, the <em>lossless WebP<\/em> format is only supported when the hosting server uses Imagick (the <span tabindex='0' class='glossary-item-container'>PHP<span class='glossary-item-hidden-content'><span class='glossary-item-header'>PHP<\/span> <span class='glossary-item-description'>The web scripting language in which WordPress is primarily architected. WordPress requires PHP 7.4 or higher<\/span><\/span><\/span> library) until LibGD <a href=\"https:\/\/github.com\/libgd\/libgd\/pull\/698\">adds support<\/a>. In addition, animated and alpha formats are not yet supported for resized images (lossy images are created instead when you upload in these formats).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WebP support in the media library requires that your web server\u2019s image processing library (WordPress supports both Imagick and LibGD) supports the WebP format. Fortunately these libraries have supported WebP for quite a while so support is widely available. If your web server does not support WebP, you will see an error message when you try to upload a WebP image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your audience includes a significant number of users on an unsupported browser (IE11 for example), either avoid using WebP images, or\u00a0 enqueue a <a href=\"https:\/\/github.com\/chase-moskal\/webp-hero\">browser polyfill<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Plans for the future<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The media component team is also exploring the option of having WordPress perform the image format conversion on uploaded images \u2013 using WebP as the default output format for sub-sized images. You can track progress and test this feature on the <a href=\"https:\/\/core.trac.wordpress.org\/ticket\/52867\">trac ticket<\/a>. We are also keeping our eyes on even more modern formats like AVIF and JPEGXL that will both improve compression and further reduce resources required for compression.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How can I fine tune the compression quality setting used for WebP images?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Developers or plugins can use the <code>wp_editor_set_quality<\/code> <span tabindex='0' class='glossary-item-container'>filter<span class='glossary-item-hidden-content'><span class='glossary-item-header'>Filter<\/span> <span class='glossary-item-description'>Filters are one of the two types of Hooks <a href=\"https:\/\/codex.wordpress.org\/Plugin_API\/Hooks\">https:\/\/codex.wordpress.org\/Plugin_API\/Hooks<\/a>. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output.<\/span><\/span><\/span> to set the quality setting. The passed mime type enables setting by type, for example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ Use a quality setting of 75 for WebP images.\nfunction filter_webp_quality( $quality, $mime_type ) {\n  if ( 'image\/webp' === $mime_type ) {\n     return 75;\n  }\n  return $quality;\n}\nadd_filter( 'wp_editor_set_quality', 'filter_webp_quality', 10, 2 );\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">What happens if I enable the filter to use WebP sub-sizes, but upload JPEG? Do the sub-sizes have to match the original?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, WordPres creates the sub-sized images of the same type as the uploaded file, so uploaded WebP files to get WebP files on your site. If you want to experiment with uploading JPEG and having WordPress auto-convert these to WebP for your sub-sized images, check out this <a href=\"https:\/\/github.com\/adamsilverstein\/wordpress-modern-images\">plugin<\/a> (related <a href=\"https:\/\/core.trac.wordpress.org\/ticket\/52867\">trac ticket<\/a>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">If I use WordPress <span tabindex='0' class='glossary-item-container'>multisite<span class='glossary-item-hidden-content'><span class='glossary-item-header'>multisite<\/span> <span class='glossary-item-description'>Used to describe a WordPress installation with a network of multiple blogs, grouped by sites. This installation type has shared users tables, and creates separate database tables for each blog (wp_posts becomes wp_0_posts). See also <strong>network<\/strong>, <strong>blog<\/strong>, <strong>site<\/strong><\/span><\/span><\/span>, will all my sites work with WebP images?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Multisite stores the file types that users are allowed to upload when a site is created. We are working on improving this in <a href=\"https:\/\/core.trac.wordpress.org\/ticket\/53167\">#53167<\/a>. In the meantime, to ensure all existing sites on a <span tabindex='0' class='glossary-item-container'>network<span class='glossary-item-hidden-content'><span class='glossary-item-header'>network<\/span> <span class='glossary-item-description'>(versus site, blog)<\/span><\/span><\/span> allow WebP files, you can use the <code>site_option<\/code> filter in a network mu-<span tabindex='0' class='glossary-item-container'>plugin<span class='glossary-item-hidden-content'><span class='glossary-item-header'>Plugin<\/span> <span class='glossary-item-description'>A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory <a href=\"https:\/\/wordpress.org\/plugins\/\">https:\/\/wordpress.org\/plugins\/<\/a> or can be cost-based plugin from a third-party.<\/span><\/span><\/span> to add <code>webp<\/code> to the allowed file types for all network sites:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ Ensure all network sites include WebP support.\nadd_filter(\n  'site_option_upload_filetypes',\n  function ( $filetypes ) {\n    $filetypes = explode( ' ', $filetypes );\n    if ( ! in_array( 'webp', $filetypes, true ) ) {\n      $filetypes[] = 'webp';\n    }\n    $filetypes \u00a0 = implode( ' ', $filetypes );\n\n    return $filetypes;\n  }\n);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<p class=\"o2-appended-tags\"><a href=\"https:\/\/make.wordpress.org\/core\/tag\/5-8\/\" class=\"tag\"><span class=\"tag-prefix\">#<\/span>5-8<\/a>, <a href=\"https:\/\/make.wordpress.org\/core\/tag\/core-images\/\" class=\"tag\"><span class=\"tag-prefix\">#<\/span>core-images<\/a>, <a href=\"https:\/\/make.wordpress.org\/core\/tag\/dev-notes\/\" class=\"tag\"><span class=\"tag-prefix\">#<\/span>dev-notes<\/a>, <a href=\"https:\/\/make.wordpress.org\/core\/tag\/images\/\" class=\"tag\"><span class=\"tag-prefix\">#<\/span>images<\/a><\/p><nav class='o2-post-footer-actions'><ul class='o2-post-footer-action-row'><\/ul><div class='o2-post-footer-action-likes'><\/div><ul class='o2-post-footer-action-row'><\/ul><\/nav>","protected":false},"excerpt":{"rendered":"<p>WebP is a modern image format that provides improved lossless and lossy compression for images on the web. WebP images are around 30% smaller on average than their JPEG or PNG equivalents, resulting in sites that are faster and use less bandwidth. WebP is supported in all modern browsers according to caniuse. From WordPress version [&hellip;]<\/p>\n","protected":false},"author":10464658,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1175],"tags":[3590,2648,1443,142],"class_list":["post-89283","post","type-post","status-publish","format-standard","hentry","category-general","tag-5-8","tag-core-images","tag-dev-notes","tag-images","mentions-adamsilverstein","author-adamsilverstein"],"revision_note":"","jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2AvED-ne3","_links":{"self":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts\/89283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/users\/10464658"}],"replies":[{"embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/comments?post=89283"}],"version-history":[{"count":19,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts\/89283\/revisions"}],"predecessor-version":[{"id":92137,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts\/89283\/revisions\/92137"}],"wp:attachment":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/media?parent=89283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/categories?post=89283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/tags?post=89283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}