Delete an attachment in the WP media modal window

Posted by Prem Tiwari | Updated on

You just have to call destroy method on the attachment model. This will both remove the attachment from the Media Library view, and send an ajax call to the backend to delete the attachment in the database and all linked files in uploads directory.

You do not need to convert the attachment to JSON to get the id : you can directly manipulate the Backbone models. The selection is a collection of several attachments.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers