{"id":139708,"date":"2016-08-24T11:00:01","date_gmt":"2016-08-24T16:00:01","guid":{"rendered":"https:\/\/getflywheel.com\/?p=18630"},"modified":"2025-05-12T14:59:13","modified_gmt":"2025-05-12T19:59:13","slug":"responsive-images-wordpress","status":"publish","type":"resource","link":"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/","title":{"rendered":"Working with Responsive Images in WordPress"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Until recently, working with responsive images in WordPress was a real challenge. Unless users were willing to write the functionality themselves, they were out of luck. The other option was to purchase a plugin or to find some other workaround, but there was no core functionality available that developers could take advantage of. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Themes created without support for responsive images were often slow performing, and usability was sometimes&nbsp;unstable across varying screen sizes. Those aren\u2019t exactly attributes that customers and users associate with good functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fortunately, this all changed with the release of WordPress 4.4. Now functionality for responsive images is included directly within WordPress, allowing developers to work with it in themes, also. This was accomplished by taking a responsive images plugin and making it part of the WordPress core.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it All Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Obviously, unless you have already done so, your first step is to update to <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/wordpress.org\/support\/topic\/read-this-first-wordpress-44-master-list\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress 4.4<\/a>. Once you have completed the update, if you view the source code of your site, you will notice that the images on your site now have two new attributes: <code>sizes<\/code> and <code>srcset<\/code>. These attributes are filtered, which means that all image sizes available are present, but that the dimensions remain consistent with the original image. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/www.sitepoint.com\/how-to-build-responsive-images-with-srcset\/\" target=\"_blank\" rel=\"noopener noreferrer\">srcset attribute<\/a> won\u2019t allow custom cropping in cases where the aspect ratio is not the same as that of the original version of the image. This is to ensure that image quality is not compromised when it\u2019s displayed on a user\u2019s screen.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2016\/08\/wordpress-responsive-images-display.jpg\" alt=\"a tablet sits on a white table\" class=\"wp-image-18637\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Under the Hood and Making Changes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress has added responsive images as a background feature, which means the process happens automatically. When you upload an image using the media uploader, the attributes are applied to those images without any intervention on your part. This is useful for image optimization, also. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because it is a background feature, responsive images do not come with a user interface\u2014they just happen. As a developer, you can modify the <code>functions.php<\/code> file in each of your themes in order to be certain that your images are given a <code>sizes<\/code> attribute that is accurate. Remember: When you want to refer to responsive images, that means the image tag attributes of <code>sizes<\/code> and <code>srcset<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Default Attributes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As you begin working with this feature, you will notice that WordPress is pretty good at finding all possible sizes and adding them to the <code>srcset<\/code> attribute. Unfortunately, problems can come into play when it comes to the predictability of the <code>sizes<\/code> attribute. This is the attribute that is used to communicate the image width to browsers so that images will be available and viewable on any display screen.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2016\/08\/wordpress-responsive-screen-sizes.jpg\" alt=\"person scrolls on a smartphone\" class=\"wp-image-18638\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Setting up this attribute as a default works in a couple of ways. The first is that it forces the <code>sizes<\/code> attribute to be applied to each image. This is helpful considering that it is now a mandatory requirement. The second is that it doesn\u2019t allow browsers to use an image source any wider than the original size of the image. CSS code that is used to tweak image size depending on display screen widths (such as media queries) can unfortunately render this default much less useful.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Filter Hooks for Theme Developers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Because this default attribute only works with images that have not been modified by CSS code, WordPress has created filter hooks for theme developers to use. You just adjust the <code>sizes<\/code> attribute for all images using this hook. As a result, you can be certain that the <code>sizes<\/code> attribute that is served up is going to be ideal in every situation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Caveat<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before moving forward, let\u2019s take a minute to state that the default attributes option is not the best way to provide good responsive image functionality. In fact, you should work to avoid creating themes that rely on this default. The reason for this is that the default attribute prevents browsers from modifying the image source when the display area is not as big as the size of the original image. Browsers are also unable to modify the source if it has been tweaked by CSS and a larger image is needed.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2016\/08\/wordpress-responsive-images-browser.jpg\" alt=\"a laptop sits on a wooden end table\" class=\"wp-image-18639\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Image Filtering<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As a theme developer, you can use filtering in your images in order to pull in a <code>sizes<\/code> attribute that is accurate. This can be accomplished by using a hook for the WordPress function, <code>wp_calculate_image_sizes<\/code>. You can use this function so that it works with your current theme. You can make changes that apply a different <code>sizes<\/code> attribute to different types of images.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">New functions that come with this release now make it possible for the <code>sizes<\/code> and <code>srcset<\/code> attributes to be applied to all images that you have added using the WordPress media uploader. It also allows you to add the attributes to images in your posts. Take a look at <code>wp_get_attachment_image_sizes<\/code>. This returns a <code>sizes<\/code> attribute that you can catch and change via a filter in the <code>functions.php<\/code> file for your theme. Likewise, <code>wp_get_attachment_image_srcset<\/code> does the same thing, only for the <code>srcset<\/code> attribute.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Responsive Images and Your Custom Theme<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The new functions that have come with this latest release are accompanied by many hooks that you can use to provide effective support for responsive images within your theme. These hooks include the following:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Wp_calculate_image_sizes<\/code> &#8211; A hook that theme developers can use to adjust the <code>sizes<\/code> attribute to work with the breakpoints that are present in their theme.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Max_srcset_image_width<\/code> &#8211; A hook that a theme developer will be able to use to filter according to the maximum width of images that are in the <code>srcset<\/code> attribute.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>W_calculate_image_srcset<\/code> &#8211; A hook that gives developers the ability to filter according to <code>srcset<\/code> attributes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Learning More About Responsive Images Support<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/developer.wordpress.org\/themes\/getting-started\/\" target=\"_blank\" rel=\"noreferrer noopener\">The WordPress developer manual<\/a> can provide more guidance when it comes to using these hooks effectively. The research that you need to do will vary depending on your comfort level in making these kinds of behind-the-scenes adjustments. If you are a theme developer who pursues this as strictly a hobby, you might opt to do a bit of experimenting. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the other hand, if you are a career theme developer, you might wish to invest in the time and resources required to truly master this update.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2016\/08\/wordpress-responsive-images-update.jpg\" alt=\"a person types on a keyboard at a Mac \" class=\"wp-image-18640\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of Updating<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you haven&#8217;t already updated WordPress (or if your <a href=\"https:\/\/wpengine.com\/managed-wordpress-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">managed hosting provider<\/a> hasn&#8217;t already updated for you), your users will benefit from some great perks when you do. Responsive image support can improve page performance as their pages won\u2019t waste time pulling down images that are too large. Users will also note a very impressive improvement in the quality of the images. They won\u2019t see the \u2018sausage making\u2019 that goes into everything. Instead, they will just see that it works nicely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As the developer, you will have to adjust the <code>sizes<\/code> attribute in each of the <code>functions.php<\/code> files for all of your themes. However, once you have made this initial effort, things become much easier. After you have tackled the learning curve, you will find that working with this new functionality comes quite naturally.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It might take some research and practice to get a hang of this new functionality, and to get responsive image support to work for your custom themes. However, if you are willing to dig around in the developer&#8217;s manual and figure things out, your clients will truly appreciate the improvement in performance and functionality. This has been a long time coming, and seasoned theme developers and those tasked with maintaining custom themes are rightly excited by this update.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Until recently, working with responsive images in WordPress was a real challenge. Unless users were willing to write the functionality themselves, they were out of luck. The other option was to purchase a plugin or to find some other workaround, but there was no core functionality available that developers could take advantage of. Themes created<span class=\"tile__ellipses\">&hellip;<\/span><span class=\"tile__ellipses--animated\"><\/span><\/p>\n","protected":false},"author":1,"featured_media":142515,"template":"","resource-topic":[1396,901],"resource-role":[895,1397,896,897],"resource-type":[916],"class_list":["post-139708","resource","type-resource","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Working with Responsive Images in WordPress<\/title>\n<meta name=\"description\" content=\"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working with Responsive Images in WordPress\" \/>\n<meta property=\"og:description\" content=\"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Engine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpengine\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-12T19:59:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2016\/08\/responsive-images-header.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Working with Responsive Images in WordPress\" \/>\n<meta name=\"twitter:description\" content=\"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2016\/08\/responsive-images-header.png\" \/>\n<meta name=\"twitter:site\" content=\"@wpengine\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/\",\"url\":\"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/\",\"name\":\"Working with Responsive Images in WordPress\",\"isPartOf\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\"},\"datePublished\":\"2016-08-24T16:00:01+00:00\",\"dateModified\":\"2025-05-12T19:59:13+00:00\",\"description\":\"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!\",\"breadcrumb\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wpengine.com\/case-studies\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Resources\",\"item\":\"https:\/\/wpengine.com\/case-studies\/resources\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Working with Responsive Images in WordPress\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\",\"url\":\"https:\/\/wpengine.com\/case-studies\/\",\"name\":\"WP Engine\",\"description\":\"Managed Hosting for WordPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085\",\"name\":\"WP Engine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"caption\":\"WP Engine\"},\"sameAs\":[\"https:\/\/wpengine.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Working with Responsive Images in WordPress","description":"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"Working with Responsive Images in WordPress","og_description":"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!","og_url":"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/","og_site_name":"WP Engine","article_publisher":"https:\/\/www.facebook.com\/wpengine","article_modified_time":"2025-05-12T19:59:13+00:00","og_image":[{"width":1100,"height":500,"url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2016\/08\/responsive-images-header.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_title":"Working with Responsive Images in WordPress","twitter_description":"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!","twitter_image":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2016\/08\/responsive-images-header.png","twitter_site":"@wpengine","twitter_misc":{"Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/","url":"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/","name":"Working with Responsive Images in WordPress","isPartOf":{"@id":"https:\/\/wpengine.com\/case-studies\/#website"},"datePublished":"2016-08-24T16:00:01+00:00","dateModified":"2025-05-12T19:59:13+00:00","description":"Working with responsive images is easier than ever before. Read all about it, then learn how to add customizations!","breadcrumb":{"@id":"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/case-studies\/resources\/responsive-images-wordpress\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/case-studies\/"},{"@type":"ListItem","position":2,"name":"Resources","item":"https:\/\/wpengine.com\/case-studies\/resources\/"},{"@type":"ListItem","position":3,"name":"Working with Responsive Images in WordPress"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/case-studies\/#website","url":"https:\/\/wpengine.com\/case-studies\/","name":"WP Engine","description":"Managed Hosting for WordPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085","name":"WP Engine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","caption":"WP Engine"},"sameAs":["https:\/\/wpengine.com"]}]}},"acf":[],"grid_image_url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2016\/08\/responsive-images-grid.png","media-type":{"term_id":916,"name":"Article","slug":"article"},"role":"<strong>Roles:<\/strong> Agency, Designer, Developer, Freelancer","topic":"<strong>Topics:<\/strong> Design, WordPress","_links":{"self":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource\/139708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource"}],"about":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/types\/resource"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/users\/1"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media\/142515"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media?parent=139708"}],"wp:term":[{"taxonomy":"resource-topic","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-topic?post=139708"},{"taxonomy":"resource-role","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-role?post=139708"},{"taxonomy":"resource-type","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-type?post=139708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}