wp_delete_attachment ( $post_id, $force_delete = false )

  • (int) post_id Attachment ID.
  • (bool) force_delete Optional. Whether to bypass Trash and force deletion. Default false.
  • (WP_Post|false|null) Post data on success, false or null on failure.
Defined at:


Trashes or deletes an attachment.When an attachment is permanently deleted, the file will also be removed. Deletion removes all post meta fields, taxonomy, comments, etc. associated with the attachment (except the main post). The attachment is moved to the Trash instead of permanently deleted unless Trash for media is disabled, item is already in the Trash, or $force_delete is true.

Related Functions

wp_delete_attachment_files, wp_delete_comment, wp_insert_attachment, wp_get_attachment_url, wp_ajax_get_attachment

Top Google Results

User discussions

wpseek mobile