I have Picture Blog with over 100k Images, All of these images are remotely hosted, and many of them contains dead links for images. I want to delete all posts that contains dead links for images, What would be the easiest way to do this in wordpress? Please let me know.

Any help would be really appreciated.

Thanks and Regards, S.M.

1 Answer 1


I'm only going to cover this in the broadest terms because I don't know the details of how the linked images appear in your site, but assuming each post contains one hotlinked image:

You need to write a script that loops through all your posts and parses the post content for a non-local URL. It needs to make a request for that URL, examine the status code returned by the request then if the status indicates that the link is broken your script will need to firstly delete the post, then implement a 301 redirect to a different URL of your choice (your homepage, the post's category or a related post) for the deleted post's permalink to avoid your own site being littered with dead links.

Interpreting the status code returned for the URL is another thing that you're going to have to fine-tune based on the policies of the image hosting sites - some will return a 404, others might do something else. The most comprehensive method would be to assume that anything that doesn't return 200 is a broken link, although that might lead to false positives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.