wp_img_tag_add_loading_attr
Filter HookDescription
Adds `loading` attribute to an `img` HTML tag. / function wp_img_tag_add_loading_attr( $image, $context ) { _deprecated_function( __FUNCTION__, '6.3.0', 'wp_img_tag_add_loading_optimization_attrs()' ); /* Get loading attribute value to use. This must occur before the conditional check below so that even images that are ineligible for being lazy-loaded are considered.Hook Information
| File Location |
wp-includes/deprecated.php
View on GitHub
|
| Hook Type | Filter |
| Line Number | 4800 |
Hook Parameters
| Type | Name | Description |
|---|---|---|
string
|
$image
|
The HTML `img` tag where the attribute should be added. |
string
|
$context
|
Additional context to pass to the filters. |
Usage Examples
Basic Usage
<?php
// Hook into wp_img_tag_add_loading_attr
add_filter('wp_img_tag_add_loading_attr', 'my_custom_filter', 10, 2);
function my_custom_filter($image, $context) {
// Your custom filtering logic here
return $image;
}
Source Code Context
wp-includes/deprecated.php:4800
- How this hook is used in WordPress core
<?php
4795 if ( ! str_contains( $image, ' src="' ) || ! str_contains( $image, ' width="' ) || ! str_contains( $image, ' height="' ) ) {
4796 return $image;
4797 }
4798
4799 /** This filter is documented in wp-admin/includes/media.php */
4800 $value = apply_filters( 'wp_img_tag_add_loading_attr', $value, $image, $context );
4801
4802 if ( $value ) {
4803 if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) {
4804 $value = 'lazy';
4805 }
PHP Documentation
<?php
/**
* Adds `loading` attribute to an `img` HTML tag.
*
* @since 5.5.0
* @deprecated 6.3.0 Use wp_img_tag_add_loading_optimization_attrs() instead.
* @see wp_img_tag_add_loading_optimization_attrs()
*
* @param string $image The HTML `img` tag where the attribute should be added.
* @param string $context Additional context to pass to the filters.
* @return string Converted `img` tag with `loading` attribute added.
*/
function wp_img_tag_add_loading_attr( $image, $context ) {
_deprecated_function( __FUNCTION__, '6.3.0', 'wp_img_tag_add_loading_optimization_attrs()' );
/*
* Get loading attribute value to use. This must occur before the conditional check below so that even images that
* are ineligible for being lazy-loaded are considered.
*/
Quick Info
- Hook Type: Filter
- Parameters: 2
- File: wp-includes/deprecated.php
Related Hooks
Related hooks will be displayed here in future updates.