If you get a WordPress media attachment page 404 error, the solution may not be obvious. I got very frustrated with the unhelpful answers I found searching on Google, so I dug deep to find my definitive solution.
After much trial-and-error checking, the issue appears: the media/image file is attached to a post or page that no longer exists. This is a subtle error, but removing the nonexistent post reference fixed all my affected image files!
Fix for WordPress Media Attachment Page 404 Error
To see the breakage easily, I used a WordPress plugin to show more details about the image file. The plugin was used to visualize the problem (the attachment to the nonexistent post) and can be used to fix the attachment issue. In my case, I deleted the attachment but could have re-attached the image to an existing post.
- Set up the Media Library Assistant plugin under the “General” tab, then scroll to “Media/Edit Media Enhancements.”
- Check the box: “Enable Edit Media additional meta boxes” – this adds “Parent Info,” “Menu Order,” “Attachment Metadata,” and four “where-used” meta boxes to the Edit Media screen.
- Go to each faulty image file and review the “Parent Info” section – observe the NONEXISTENT attachment!
- Fix the attachment as you wish.
Also, go to “Media,” then “Assistant” to observe, under the “Title/Name” column, the status of the media attachment, including UNATTACHED. (This menu item, “Assistant”, is available with the Media Library Assistant plugin installed.)
How This Happens
Media such as images uploaded by various plugins may create a “Page” or “Collection,” which you may delete later but keep the image. In my case, I deleted such pages after the fact. The plugins were likely performing as described.