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 |
|---|---|
| 1147 | |
| 1148 | if ( empty( $attr['sizes'] ) ) { |
| 1149 | $attr['sizes'] = $sizes; |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | /** This filter is documented in wp-includes/media.php */ |
| 1156 | $add_auto_sizes = apply_filters( 'wp_img_tag_add_auto_sizes', true ); |
| 1157 | |
| 1158 | // Adds 'auto' to the sizes attribute if applicable. |
| 1159 | if ( |
| 1160 | $add_auto_sizes && |
| 1161 | isset( $attr['loading'] ) && |
| 1162 | 'lazy' === $attr['loading'] && |
| 1163 | isset( $attr['sizes'] ) && |
| 1164 | ! wp_sizes_attribute_includes_valid_auto( $attr['sizes'] ) |
| 1165 | ) { |
| Line | Code |
| 2015 | */ |
| 2016 | function wp_img_tag_add_auto_sizes( string $image ): string { |
| 2017 | /** |
| 2018 | * Filters whether auto-sizes for lazy loaded images is enabled. |
| 2019 | * |
| 2020 | * @since 6.7.1 |
| 2021 | * |
| 2022 | * @param boolean $enabled Whether auto-sizes for lazy loaded images is enabled. |
| 2023 | */ |
| 2024 | if ( ! apply_filters( 'wp_img_tag_add_auto_sizes', true ) ) { |
| 2025 | return $image; |
| 2026 | } |
| 2027 | |
| 2028 | $processor = new WP_HTML_Tag_Processor( $image ); |
| 2029 | |
| 2030 | // Bail if there is no IMG tag. |
| 2031 | if ( ! $processor->next_tag( array( 'tag_name' => 'IMG' ) ) ) { |
| 2032 | return $image; |
| 2033 | } |
| Line | Code |
| 2095 | function wp_enqueue_img_auto_sizes_contain_css_fix(): void { |
| 2096 | // Back-compat for plugins that disable functionality by unhooking this action. |
| 2097 | $priority = has_action( 'wp_head', 'wp_print_auto_sizes_contain_css_fix' ); |
| 2098 | if ( false === $priority ) { |
| 2099 | return; |
| 2100 | } |
| 2101 | remove_action( 'wp_head', 'wp_print_auto_sizes_contain_css_fix', $priority ); |
| 2102 | |
| 2103 | /** This filter is documented in wp-includes/media.php */ |
| 2104 | $add_auto_sizes = apply_filters( 'wp_img_tag_add_auto_sizes', true ); |
| 2105 | if ( ! $add_auto_sizes ) { |
| 2106 | return; |
| 2107 | } |
| 2108 | |
| 2109 | $handle = 'wp-img-auto-sizes-contain'; |
| 2110 | wp_register_style( $handle, false ); |
| 2111 | wp_add_inline_style( $handle, 'img:is([sizes=auto i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}' ); |
| 2112 | |
| 2113 | // Make sure inline style is printed first since it was previously printed at wp_head priority 1 and this preserves the CSS cascade. |