W3cubDocs

/WordPress

wp_lazy_loading_enabled( string $tag_name, string $context ): bool

Determines whether to add the loading attribute to the specified tag in the specified context.

Parameters

$tag_namestringrequired
The tag name.
$contextstringrequired
Additional context, like the current filter name or the function name from where this was called.

Return

bool Whether to add the attribute.

Source

		// Format the 'srcset' and 'sizes' string and escape attributes.
		$attr = sprintf( ' srcset="%s"', esc_attr( $srcset ) );

		if ( is_string( $sizes ) ) {
			$attr .= sprintf( ' sizes="%s"', esc_attr( $sizes ) );
		}

		// Add the srcset and sizes attributes to the image markup.
		return preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image );
	}

	return $image;
}

/**
 * Determines whether to add the `loading` attribute to the specified tag in the specified context.
 *
 * @since 5.5.0
 * @since 5.7.0 Now returns `true` by default for `iframe` tags.
 *

Changelog

Version Description
5.7.0 Now returns true by default for iframe tags.
5.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_lazy_loading_enabled