Title: rest_insert_attachment
Published: December 6, 2016
Last modified: February 24, 2026

---

# do_action( ‘rest_insert_attachment’, WP_Post $attachment, WP_REST_Request $request, bool $creating )

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/hooks/rest_insert_attachment/?output_format=md#wp--skip-link--target)

Fires after a single attachment is created or updated via the REST API.

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

 `$attachment`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)

Inserted or updated attachment object.

`$request`[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)

The request sent to the API.

`$creating`bool

True when creating an attachment, false when updating.

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

    ```php
    do_action( 'rest_insert_attachment', $attachment, $request, true );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L396)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L396-L396)

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

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

Inserts the attachment post in the database. Does not update the attachment meta.

  |

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

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

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