Home » Wordpress » remove duplicate images from wordpress media library

remove duplicate images from wordpress media library

Posted by: admin November 30, 2017 Leave a comment


I want to know about that how to remove duplicate images from wordpress media library and i also want to ask that how media uploader checks duplication of file.

Get all posts. See get_posts( array ( 'numberposts' => -1 ) )
For each post get all attachments. See get_children( array ( 'post_type' => 'attachment', 'numberposts' => -1 ) )
For each attachment get the attachment URL. See wp_get_attachment_url()
If you find the attachment URL in the parent post's content ($post->post_content):
    If there is another attachment URL with the same file name plus the 1 and
    both are part of the post content then
    remove the second image first then
    use wp_delete_attachment() to delete the physical file. This will remove all meta data and all associations in other posts too. It is the best way to remove attached files (imho).


Clean up unused images and other files from your uploads folder.


Delete not used image


when not use plugin:

go media:   Sort files by Unattached.

delete which is not used.

Leave a Reply

Your email address will not be published. Required fields are marked *