If you would like to talk about your project call (02) 4474 5861
The following is a snippet from Responsive Images in WordPress 4.4
WordPress 4.4 will add native responsive image support by including srcset and sizes attributes to the image markup it generates.
To implement this feature, we’ve added the following new functions to WordPress:
As a safeguard against adding very large images to srcset attributes, we’ve included a max_srcset_image_width filter, which allows themes to set a maximum image width for images include in source set lists. The default value is 1600px.
To modify the default srcset and sizes attributes, you should use the wp_calculate_image_srcset and wp_calculate_image_sizes filters, respectively.
Overriding the srcset or sizes attributes for images not embedded in post content (e.g. post thumbnails, galleries, etc.), can be accomplished using the wp_get_attachment_image_attributes filter, similar to how other image attributes are modified.
Additionally, you can create your own custom markup patterns by using wp_get_attachment_image_srcset() directly in your templates. Here is an example of how you could use this function to build an element with a custom sizes attribute:
$img_src = wp_get_attachment_image_url( $attachment_id, 'medium' );
$img_srcset = wp_get_attachment_image_srcset( $attachment_id, 'medium' );
<img src="<?php echo esc_attr( $img_src ); ?>"
srcset="<?php echo esc_attr( $img_srcset ); ?>"
sizes="(max-width: 50em) 87vw, 680px" alt="A rad wolf">
Last updated on
Visually communicating effectively with your potential & current customers adds to the good business experience.
BJ2DESIGN combines a wealth of design knowledge with creative business strategies to create result oriented work.