wp_lazy_loading_enabled() WordPress Function

This function enables lazy loading for images in Wordpress. When enabled, images will not be loaded until they are visible on the screen. This can improve performance, especially on mobile devices.

wp_lazy_loading_enabled( string $tag_name, string $context ) #

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


Parameters

$tag_name

(string)(Required)The tag name.

$context

(string)(Required)Additional context, like the current filter name or the function name from where this was called.


Top ↑

Return

(bool) Whether to add the attribute.


Top ↑

Source

File: wp-includes/media.php

function wp_lazy_loading_enabled( $tag_name, $context ) {
	// By default add to all 'img' and 'iframe' tags.
	// See https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-loading
	// See https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-loading
	$default = ( 'img' === $tag_name || 'iframe' === $tag_name );

	/**
	 * Filters whether to add the `loading` attribute to the specified tag in the specified context.
	 *
	 * @since 5.5.0
	 *
	 * @param bool   $default  Default value.
	 * @param string $tag_name The tag name.
	 * @param string $context  Additional context, like the current filter name
	 *                         or the function name from where this was called.
	 */
	return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );
}


Top ↑

Changelog

Changelog
VersionDescription
5.7.0Now returns true by default for iframe tags.
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More