Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: wp_img_tag_add_loading_attr

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

Line Code
1833       * Returning `true` will add the default value.
1834       *
1835       * @since 5.5.0
1836       *
1837       * @param string|bool $value   The `loading` attribute value. Returning a falsey value will result in
1838       *                             the attribute being omitted for the image. Default 'lazy'.
1839       * @param string      $image   The HTML `img` tag to be filtered.
1840       * @param string      $context Additional context about how the function was called or where the img tag is.
1841       */
1842      $value = apply_filters( 'wp_img_tag_add_loading_attr', 'lazy', $image, $context );
1843
1844      if ( $value ) {
1845           if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) {
1846                $value = 'lazy';
1847           }
1848
1849           // Images should have source and dimension attributes for the `loading` attribute to be added.
1850           if ( false === strpos( $image, ' src="' ) || false === strpos( $image, ' width="' ) || false === strpos( $image, ' height="' ) ) {
1851                return $image;