wp_get_attachment_image
Filter HookDescription
Filters the HTML img element representing an image attachment.Hook Information
File Location |
wp-includes/media.php
View on GitHub
|
Hook Type | Filter |
Line Number | 1201 |
Hook Parameters
Type | Name | Description |
---|---|---|
string
|
$html
|
HTML img element or empty string on failure. |
int
|
$attachment_id
|
Image attachment ID. |
string|int[]
|
$size
|
Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order). |
bool
|
$icon
|
Whether the image should be treated as an icon. |
string[]
|
$attr
|
Array of attribute values for the image markup, keyed by attribute name. See wp_get_attachment_image(). |
Usage Examples
Basic Usage
<?php
// Hook into wp_get_attachment_image
add_filter('wp_get_attachment_image', 'my_custom_filter', 10, 5);
function my_custom_filter($html, $attachment_id, $size, $icon, $attr) {
// Your custom filtering logic here
return $html;
}
Source Code Context
wp-includes/media.php:1201
- How this hook is used in WordPress core
<?php
1196 * an array of width and height values in pixels (in that order).
1197 * @param bool $icon Whether the image should be treated as an icon.
1198 * @param string[] $attr Array of attribute values for the image markup, keyed by attribute name.
1199 * See wp_get_attachment_image().
1200 */
1201 return apply_filters( 'wp_get_attachment_image', $html, $attachment_id, $size, $icon, $attr );
1202 }
1203
1204 /**
1205 * Gets the URL of an image attachment.
1206 *
PHP Documentation
<?php
/**
* Filters the HTML img element representing an image attachment.
*
* @since 5.6.0
*
* @param string $html HTML img element or empty string on failure.
* @param int $attachment_id Image attachment ID.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
* @param bool $icon Whether the image should be treated as an icon.
* @param string[] $attr Array of attribute values for the image markup, keyed by attribute name.
* See wp_get_attachment_image().
*/
Quick Info
- Hook Type: Filter
- Parameters: 5
- File: wp-includes/media.php
Related Hooks
Related hooks will be displayed here in future updates.