Filter hook 'wp_content_img_tag'

in WP Core File wp-includes/media.php at line 1957

View Source

wp_content_img_tag

Filter Hook
Description
Filters an img tag within the content for a given context.

Hook Information

File Location wp-includes/media.php View on GitHub
Hook Type Filter
Line Number 1957

Hook Parameters

Type Name Description
string $filtered_image Full img tag with attributes that will replace the source img tag.
string $context Additional context, like the current filter name or the function name from where this was called.
int $attachment_id The image attachment ID. May be 0 in case the image is not an attachment.

Usage Examples

Basic Usage
<?php
// Hook into wp_content_img_tag
add_filter('wp_content_img_tag', 'my_custom_filter', 10, 3);

function my_custom_filter($filtered_image, $context, $attachment_id) {
    // Your custom filtering logic here
    return $filtered_image;
}

Source Code Context

wp-includes/media.php:1957 - How this hook is used in WordPress core
<?php
1952  			 *
1953  			 * @param string $filtered_image Full img tag with attributes that will replace the source img tag.
1954  			 * @param string $context        Additional context, like the current filter name or the function name from where this was called.
1955  			 * @param int    $attachment_id  The image attachment ID. May be 0 in case the image is not an attachment.
1956  			 */
1957  			$filtered_image = apply_filters( 'wp_content_img_tag', $filtered_image, $context, $attachment_id );
1958  
1959  			if ( $filtered_image !== $match[0] ) {
1960  				$content = str_replace( $match[0], $filtered_image, $content );
1961  			}
1962  

PHP Documentation

<?php
/**
			 * Filters an img tag within the content for a given context.
			 *
			 * @since 6.0.0
			 *
			 * @param string $filtered_image Full img tag with attributes that will replace the source img tag.
			 * @param string $context        Additional context, like the current filter name or the function name from where this was called.
			 * @param int    $attachment_id  The image attachment ID. May be 0 in case the image is not an attachment.
			 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/media.php
Related Hooks

Related hooks will be displayed here in future updates.