WordPress action & filter hook · part of WordPress core
wp_generate_attachment_metadata
A WordPress core action & filter that 21 plugins also fire themselves, running on 569K+ sites between them.
“This filter is documented in wp-admin/includes/image.php”
How to use wp_generate_attachment_metadata
It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value.
Add this to your theme's functions.php or a small custom plugin:
add_filter( 'wp_generate_attachment_metadata', function( $metadata, $attachment_id ) {
// Change $metadata here.
return $metadata;
}, 10, 2 );Argument names come from Gallery by BestWebSoft'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 →
21 plugins that fire wp_generate_attachment_metadata
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Gutenberg400,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'update' )lib/media/class-gutenberg-rest-attachments-controller.php:1687 -
Simple Image Sizes60,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' )classes/Admin/Main.php:331 -
Image Watermark40,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $plan['metadata'], $attachment_id, 'update' )includes/class-upload-handler.php:16110 -
AJAX Thumbnail Rebuild30,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'update' )includes/class-atr-regenerator.php:156 -
Nexter Extension10,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $thumbnail_metadata, $thumbnail_id, 'update' )include/panel-settings/extensions/nexter-ext-image-sizes.php:363 -
Gallery by BestWebSoft10,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id )gallery-plugin.php:3643 -
Classified Listing8,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $image_meta, $attachment_id, 'create' )app/Traits/Functions/MediaTrait.php:385 -
Plus WebP or AVIF5,000+ installs
do_action( 'wp_generate_attachment_metadata', $metadata_org, $attach_id )lib/class-pluswebpadmin.php:259 -
Cowboy MCP2,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' )includes/class-mcp-compat.php:584 -
MStore API2,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $attachment, $attachment_id, 'create' )functions/index.php:1628 -
WPCOM Member1,000+ installs
apply_filters( 'wp_generate_attachment_metadata', $mirror, 0, 'create' )includes/class-member.php:1352 -
Portfolio by BestWebSoft600+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id )portfolio.php:1589 -
Thumbnail Manager200+ installs
apply_filters( 'wp_generate_attachment_metadata', $proposed, $snapshot['attachment_id'], 'update' )inc/media/regeneration.php:397 -
GrandPlugins Image Watermark200+ installs
apply_filters( 'wp_generate_attachment_metadata', $image_metadata, $attachment_id, 'update' )includes/class-single-apply-watermarks.php:304 -
Large Images Uploader100+ installs
apply_filters( 'wp_generate_attachment_metadata', $image_meta, self::$current_attachment_id, 'update' )includes/WP_Large_Images_Uploader.php:286 -
Ad King Pro100+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment->ID )includes/admin_area.php:343 -
Generate Thumbnail20+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id )admin/includes/getmbl-admin-functions.php:97 -
Blaminhor Essentials20+ installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' )modules/image-sizes/class-module-image-sizes.php:695 -
Cloage WordPress PluginFewer than 10 installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id )includes/Media/Attachment/Attachment.php:348 -
Linko Media Path Mapper & SwapperFewer than 10 installs
do_action( 'wp_generate_attachment_metadata', $attach_data, $current_id )includes/class-ajax-handler.php:565 -
Kodlo Media ReplaceFewer than 10 installs
apply_filters( 'wp_generate_attachment_metadata', $meta, $id, 'create' )kodlo-media-replace.php:522 -
CodePros Image OptimizerFewer than 10 installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'cpiop_webp_conversion' )includes/Ajax/AjaxHelper.php:44 -
Npcink Site ToolboxFewer than 10 installs
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'update' )admin/partials/performance/media_health/webp_batch.php:185
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.