Title: wp_generate_attachment_metadata
Published: April 25, 2014
Last modified: August 20, 2026

---

# apply_filters( ‘wp_generate_attachment_metadata’, array $metadata, int $attachment_id, string $context )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#changelog)

Filters the generated attachment meta data.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#parameters)󠁿

 `$metadata`array

An array of attachment meta data.

`$attachment_id`int

Current attachment ID.

`$context`string

Additional context. Can be `'create'` when metadata was initially created for new
attachment or `'update'` when the metadata was updated.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#source)󠁿

    ```php
    return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/image.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/image.php#L750)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/image.php#L750-L750)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Attachments_Controller::finalize_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/finalize_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Finalizes an attachment after client-side media processing.

  | 
| [wp_update_image_subsizes()](https://developer.wordpress.org/reference/functions/wp_update_image_subsizes/)`wp-admin/includes/image.php` |

If any of the currently registered image sub-sizes are missing, create them and update the image meta data.

  | 
| [wp_generate_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_generate_attachment_metadata/)`wp-admin/includes/image.php` |

Generates attachment meta data and create image sub-sizes for images.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/wp_generate_attachment_metadata/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | The `$context` parameter was added. | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_generate_attachment_metadata%2F)
before being able to contribute a note or feedback.