Adds srcset
and sizes
attributes to an existing img
HTML tag.
Parameters
$image
stringrequired- The HTML
img
tag where the attribute should be added. $context
stringrequired- Additional context to pass to the filters.
$attachment_id
intrequired- Image attachment ID.
Source
'6.3.0'
);
}
// The filtered value will still be respected.
$optimization_attrs['loading'] = $filtered_loading_attr;
}
if ( ! empty( $optimization_attrs['loading'] ) ) {
$image = str_replace( '<img', '<img loading="' . esc_attr( $optimization_attrs['loading'] ) . '"', $image );
}
}
if ( empty( $fetchpriority_val ) && ! empty( $optimization_attrs['fetchpriority'] ) ) {
$image = str_replace( '<img', '<img fetchpriority="' . esc_attr( $optimization_attrs['fetchpriority'] ) . '"', $image );
}
return $image;
}
/**
* Adds `width` and `height` attributes to an `img` HTML tag.
Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.