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
1810       * Returning `true` will add the default value.
1811       *
1812       * @since 5.5.0
1813       *
1814       * @param string|bool $value   The `loading` attribute value. Returning a falsey value will result in
1815       *                             the attribute being omitted for the image. Default is `lazy`.
1816       * @param string      $image   The HTML `img` tag to be filtered.
1817       * @param string      $context Additional context about how the function was called or where the img tag is.
1818       */
1819      $value = apply_filters( 'wp_img_tag_add_loading_attr', 'lazy', $image, $context );
1820
1821      if ( $value ) {
1822           if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) {
1823                $value = 'lazy';
1824           }
1825
1826           // Images should have source and dimension attributes for the `loading` attribute to be added.
1827           if ( false === strpos( $image, ' src="' ) || false === strpos( $image, ' width="' ) || false === strpos( $image, ' height="' ) ) {
1828                return $image;