WP hooks navigation: Home/browse • Actions index • Filters index
To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).
The best way to understand what a hook does is to look at where it occurs in the source code.
do_action( "hook_name" )apply_filters( "hook_name", "what_to_filter" ).Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.
This hook occurs 3 times in this file.
| Line | Code |
|---|---|
| 1137 | |
| 1138 | if ( empty( $attr['sizes'] ) ) { |
| 1139 | $attr['sizes'] = $sizes; |
| 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | /** This filter is documented in wp-includes/media.php */ |
| 1146 | $add_auto_sizes = apply_filters( 'wp_img_tag_add_auto_sizes', true ); |
| 1147 | |
| 1148 | // Adds 'auto' to the sizes attribute if applicable. |
| 1149 | if ( |
| 1150 | $add_auto_sizes && |
| 1151 | isset( $attr['loading'] ) && |
| 1152 | 'lazy' === $attr['loading'] && |
| 1153 | isset( $attr['sizes'] ) && |
| 1154 | ! wp_sizes_attribute_includes_valid_auto( $attr['sizes'] ) |
| 1155 | ) { |
| Line | Code |
| 1995 | */ |
| 1996 | function wp_img_tag_add_auto_sizes( string $image ): string { |
| 1997 | /** |
| 1998 | * Filters whether auto-sizes for lazy loaded images is enabled. |
| 1999 | * |
| 2000 | * @since 6.7.1 |
| 2001 | * |
| 2002 | * @param boolean $enabled Whether auto-sizes for lazy loaded images is enabled. |
| 2003 | */ |
| 2004 | if ( ! apply_filters( 'wp_img_tag_add_auto_sizes', true ) ) { |
| 2005 | return $image; |
| 2006 | } |
| 2007 | |
| 2008 | $processor = new WP_HTML_Tag_Processor( $image ); |
| 2009 | |
| 2010 | // Bail if there is no IMG tag. |
| 2011 | if ( ! $processor->next_tag( array( 'tag_name' => 'IMG' ) ) ) { |
| 2012 | return $image; |
| 2013 | } |
| Line | Code |
| 2066 | * This rule overrides the similar rule in the default user agent stylesheet, to avoid images that use e.g. |
| 2067 | * `width: auto` or `width: fit-content` to appear smaller. |
| 2068 | * |
| 2069 | * @since 6.7.1 |
| 2070 | * @see https://html.spec.whatwg.org/multipage/rendering.html#img-contain-size |
| 2071 | * @see https://core.trac.wordpress.org/ticket/62413 |
| 2072 | */ |
| 2073 | function wp_print_auto_sizes_contain_css_fix() { |
| 2074 | /** This filter is documented in wp-includes/media.php */ |
| 2075 | $add_auto_sizes = apply_filters( 'wp_img_tag_add_auto_sizes', true ); |
| 2076 | if ( ! $add_auto_sizes ) { |
| 2077 | return; |
| 2078 | } |
| 2079 | |
| 2080 | ?> |
| 2081 | <style>img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-size: 3000px 1500px }</style> |
| 2082 | <?php |
| 2083 | } |
| 2084 | |