Image still linked as attachment to page even though it has been deleted

I have been working on an image gallery feature where I grab images which are attached to pages and display them in various places via the get_posts() function. However, I am finding that when I remove images from the page that they have been placed that they still seem to be set as attachments. I’m just wondering if there’s something I’m mis-understanding about attachments or if this is buggy behaviour?

It may be worth me adding that I am getting images as attachments of pages because I need to be able to categorise the images and display them via categories in different places on the site. If I was able to categorise images directly I realise I wouldn’t need to worry about this problem I’m encountering!

3 Answers
3

Deleting an image from a post or page is a confusing process. When you upload an image to a post/page, it’s added to that post/page’s gallery. You can then insert the image into the content of the post/page and edit content as you see fit. When you click on the image in the wysiwyg editor, you’ll see two icons – one to edit the image’s settings and one to remove it from the editor – this second icon does not delete the image even though it looks like a typical “delete” icon.

When you press that “delete” button, it removes the image from the visual editor but keeps it in the post/page’s gallery.

To actually remove/delete the image, you need to do the following

  • Click the “Add Image” button to view the image screen
  • Click the “Gallery” tab to view what images are currently attached to the post
  • Click the “Show” link for the image you want removed.
  • Click “Delete” towards the bottom of the image detail screen

You’ll be asked to confirm deletion, then the image will be unattached to the post/page and removed entirely from WordPress.

Leave a Comment