WordPress filter hook · part of WordPress core

wp_get_attachment_image_attributes

A WordPress core filter that 19 plugins also fire themselves, running on 188K+ sites between them.

“Filters the list of attachment image attributes.”

How to use wp_get_attachment_image_attributes

It's a filter: your callback receives the value and 2 more arguments, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment, $size ) {
	// Change $attr here.
	return $attr;
}, 10, 3 );

Argument names come from SureCart's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

19 plugins that fire wp_get_attachment_image_attributes

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. SureCart icon SureCart70,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ) app/src/Models/GalleryItemImageAttachment.php:246
  2. RSS Aggregator by Feedzy icon RSS Aggregator by Feedzy40,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, '', '' ) includes/feedzy-rss-feeds-feed-tweaks.php:89
  3. Master Addons for Elementor icon Master Addons for Elementor30,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ) addons/media/ma-advanced-image/ma-advanced-image.php:1529
  4. All-in-One Video Gallery icon All-in-One Video Gallery20,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, NULL, $size ) public/public.php:1021
  5. Team icon Team10,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $fImgSize ) app/Helpers/Fns.php:1560
  6. ShopBuilder icon ShopBuilder10,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $f_img_size ) app/Helpers/Fns.php:1948
  7. Media Search Enhanced icon Media Search Enhanced5,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size ) public/class-media-search-enhanced.php:394
  8. Food Menu icon Food Menu2,000+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $fImgSize ) app/Helpers/Fns.php:1192
  9. AMP WP icon AMP WP600+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ) includes/components/class-amp-wp-img-component.php:257
  10. Just Responsive Images icon Just Responsive Images500+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $this->attachment, $this->rwd_set->key ) models/RwdImage.php:133
  11. Gym Builder icon Gym Builder100+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $gbImgSize ) inc/Controllers/Helpers/Helper.php:414
  12. DocBooker icon DocBooker90+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $wpddbImgSize ) app/Controllers/Helper/Helper.php:501
  13. Presswell Art Direction icon Presswell Art Direction80+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $image, $size_key ) includes/traits/trait-image-render.php:56
  14. AiO Podcast Studio: All-in-One Podcast Manager, Player & Publisher icon AiO Podcast Studio: All-in-One Podcast Manager, Player & Publisher10+ installs apply_filters( 'wp_get_attachment_image_attributes', $attributes, null, $size ) public/public.php:990
  15. Responsive Images icon Responsive Images10+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ) ChangeResponsiveImages.class.php:61
  16. Media Search Plus icon Media Search Plus10+ installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size ) media-search-plus.php:231
  17. GridBox Elementor Widgets icon GridBox Elementor WidgetsFewer than 10 installs apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ) includes/functions.php:205
  18. Simple Video Post icon Simple Video PostFewer than 10 installs apply_filters( 'wp_get_attachment_image_attributes', $attr, NULL, $size ) public/public.php:249
  19. ShareIt Easy icon ShareIt EasyFewer than 10 installs apply_filters( 'wp_get_attachment_image_attributes', $attr, null, 'thumbnail' ) includes/shareit-easy-content.php:91

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.