You appear to be a bot. Output may be restricted
Description
Filters the list of attachment image attributes.
Usage
$string[] = twenty_twenty_one_get_attachment_image_attributes( $attr, $attachment, $size );
Parameters
- $attr
- ( string[] ) required – Array of attribute values for the image markup, keyed by attribute name. See wp_get_attachment_image().
- $attachment
- ( WP_Post ) required – Image attachment post.
- $size
- ( string|int[] ) required – Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
Returns
string[] The filtered attributes for the image markup.
Source
File name: twentytwentyone/inc/template-functions.php
Lines:
1 to 33 of 33
function twenty_twenty_one_get_attachment_image_attributes( $attr, $attachment, $size ) { if ( is_admin() ) { return $attr; } if ( isset( $attr['class'] ) && false !== strpos( $attr['class'], 'custom-logo' ) ) { return $attr; } $width = false; $height = false; if ( is_array( $size ) ) { $width = (int) $size[0]; $height = (int) $size[1]; } elseif ( $attachment && is_object( $attachment ) && $attachment->ID ) { $meta = wp_get_attachment_metadata( $attachment->ID ); if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) { $width = (int) $meta['width']; $height = (int) $meta['height']; } } if ( $width && $height ) { // Add style. $attr['style'] = isset( $attr['style'] ) ? $attr['style'] : ''; $attr['style'] = 'width:100%;height:' . round( 100 * $height / $width, 2 ) . '%;max-width:' . $width . 'px;' . $attr['style']; } return $attr; }