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 5 times in this file.
Line | Code |
---|---|
5743 |
|
5744 | $loading_attrs = array(); |
5745 |
|
5746 | /* |
5747 | * Skip lazy-loading for the overall block template, as it is handled more granularly. |
5748 | * The skip is also applicable for `fetchpriority`. |
5749 | */ |
5750 | if ( 'template' === $context ) { |
5751 | /** This filter is documented in wp-includes/media.php */ |
5752 | return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); |
5753 | } |
5754 |
|
5755 | // For now this function only supports images and iframes. |
5756 | if ( 'img' !== $tag_name && 'iframe' !== $tag_name ) { |
5757 | /** This filter is documented in wp-includes/media.php */ |
5758 | return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); |
5759 | } |
5760 |
|
5761 | /* |
5762 | * Skip programmatically created images within content blobs as they need to be handled together with the other |
5763 | * images within the post content or widget content. |
5764 | * Without this clause, they would already be considered within their own context which skews the image count and |
5765 | * can result in the first post content image being lazy-loaded or an image further down the page being marked as a |
5766 | * high priority. |
5767 | */ |
5768 | if ( |
5769 | 'the_content' !== $context && doing_filter( 'the_content' ) || |
5770 | 'widget_text_content' !== $context && doing_filter( 'widget_text_content' ) || |
5771 | 'widget_block_content' !== $context && doing_filter( 'widget_block_content' ) |
5772 | ) { |
5773 | /** This filter is documented in wp-includes/media.php */ |
5774 | return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); |
5775 |
|
5776 | } |
5777 |
|
5778 | /* |
5779 | * Add `decoding` with a value of "async" for every image unless it has a |
5780 | * conflicting `decoding` attribute already present. |
5781 | */ |
5782 | if ( 'img' === $tag_name ) { |
5783 | if ( isset( $attr['decoding'] ) ) { |
5784 | $loading_attrs['decoding'] = $attr['decoding']; |
5785 | } else { |
5786 | $loading_attrs['decoding'] = 'async'; |
5787 | } |
5788 | } |
5789 |
|
5790 | // For any resources, width and height must be provided, to avoid layout shifts. |
5791 | if ( ! isset( $attr['width'], $attr['height'] ) ) { |
5792 | /** This filter is documented in wp-includes/media.php */ |
5793 | return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); |
5794 | } |
5795 |
|
5796 | /* |
5797 | * The key function logic starts here. |
5798 | */ |
5799 | $maybe_in_viewport = null; |
5800 | $increase_count = false; |
5801 | $maybe_increase_count = false; |
5802 |
|
Line | Code |
5929 | * Filters the loading optimization attributes. |
5930 | * |
5931 | * @since 6.4.0 |
5932 | * |
5933 | * @param array $loading_attrs The loading optimization attributes. |
5934 | * @param string $tag_name The tag name. |
5935 | * @param array $attr Array of the attributes for the tag. |
5936 | * @param string $context Context for the element for which the loading optimization attribute is requested. |
5937 | */ |
5938 | return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); |
5939 | } |
5940 |
|
5941 | /** |
5942 | * Gets the threshold for how many of the first content media elements to not lazy-load. |
5943 | * |
5944 | * This function runs the {@see 'wp_omit_loading_attr_threshold'} filter, which uses a default threshold value of 3. |
5945 | * The filter is only run once per page load, unless the `$force` parameter is used. |
5946 | * |
5947 | * @since 5.9.0 |