anand bhoraniya
anand bhoraniya

Reputation: 101

remove duplicate images from wordpress media library

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.

Upvotes: 3

Views: 6405

Answers (2)

Ravi Patel
Ravi Patel

Reputation: 5211

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

http://wordpress.org/plugins/upload-janitor/

Delete not used image

http://wordpress.org/plugins/dnui-delete-not-used-image-wordpress/screenshots/

when not use plugin:

go media:   Sort files by Unattached.

delete which is not used.

Upvotes: 0

Falguni Panchal
Falguni Panchal

Reputation: 8981

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).

Upvotes: 1

Related Questions