WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/wp delete attachment

Contents

Description

This function deletes an attachment and all of its derivatives.

Usage

 <?php wp_delete_attachment$attachmentid$force_delete ); ?> 

Parameters

$attachmentid
(integer) (required) The ID of the attachment you would like to delete.
Default: None
$force_delete
(bool) (optional) Whether to bypass trash and force deletion (added in WordPress 2.9).
Default: false

Return Values

Returns false on failure, post data on success. This should be checked using the identity operator ( === ) instead of the normal equality operator because of the possibility of a returned 0 or empty array:

<?php if ( false === wp_delete_attachment( $attachmentid ) ) do something; ?>

Hooks

This function fires the delete_attachment action hook, passing the attachment's ID ($postid).

Example

To delete an attachment with an ID of '76':

<?php wp_delete_attachment( 76 ); ?>

Source File

wp_delete_attachment() is located in wp-includes/post.php.

Related

wp_get_attachment_url()

See also index of Function Reference and index of Template Tags.