Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
attachment_url_to_postid() Simple Example
$attachment_id = attachment_url_to_postid( '' );
if ( $attachment_id ) {
// This file was found in the WordPress media library
// In this example we are going to permanently delete this file from the WordPress media library.
// Please be careful if you are copying/pasting this example code!
wp_delete_attachment( $attachment_id, true );
} else {
// This file wasn't found in the WordPress media library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.