Codex

Function Reference/wp delete attachment

Contents

Description

This function deletes an attachment

Usage

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

Parameters

$postid
(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

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 ); ?>

Related

wp_get_attachment_url()

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