The Problem With Image Attachments In WordPress

Something I’ve wanted to see in WordPress for a long time is the ability to determine which posts an image is being used on. WordPress 4.0 is expected to ship by the end of August and contains two subtle changes to image data in the media library. You’ll be able to view the author who uploaded the image and the post parent ID it’s attached to.

Uploaded By and Uploaded To Informatiom
Uploaded By and Uploaded To Information

I find this information to be useful, especially for multi-author websites. Although you can view the parent post ID the image is attached to, you can’t locate each post the image is used on. It’s important to note the difference between an image attached to a post and using an image already available in the media library.

Why Knowing Where An Image Is Used Comes In Handy

Let’s say I use a featured image for a post and it’s the featured image for several other posts. If I want to change the featured image in one post and have it change in every other post, I can’t. I also can’t change the image for specific posts automatically, it’s either all or nothing. I can’t determine which posts are using the image because WordPress only sees it being used on the parent post. This is due to the attachment relationship.

In other words, the first post the image is attached to is the only information WordPress has on where it’s being used. I could browse to every post and manually change it but my memory isn’t that good and it’s a tedious process.

The History Behind The Dilemma

In trying to figure out why this is, Justin Tadlock pointed out two Trac tickets, 10657 and 14513. Both contain lengthy, technical discussions, on how to add support for many-to-many relationships between posts and attachments in WordPress. Within the discussions, the Posts 2 Posts plugin is commonly referred to as a top-notch plugin that offers this functionality.

Before the Community Summit in October of 2012, Andrew Nacin and a host of other WordPress developers came together to discuss the subject in detail. The ideas brought forth from that conversation are available on the Make.WordPress.com blog and is a potential roadmap for taxonomy meta and post relationships in WordPress.

It’s Possible But Not Worth The Hassle

WordPress automatically renames files if it detects the same name being used in the media library. This means you can’t upload a new image with the same file name to replace it. An alternative method is to use FTP to locate the original file and overwrite it, keeping the same name. The image will change in all posts using it, regardless of the attachment details. You’ll also need to overwrite any images that were resized automatically by WordPress or else they’ll show up instead of the new ones.

After performing all sorts of tests in my local environment for trying to change one image across multiple posts, I’ve decided it’s too much of a hassle. Not being able to manage these relationships in WordPress doesn’t make sense. Ideally, I’d like to be able to determine which posts are using an image and replace that image across all of those posts at the same time. I also wouldn’t mind the flexibility to change an image for certain posts while leaving the others alone.

19

19 responses to “The Problem With Image Attachments In WordPress”

  1. This is fabulous. I’ve been wanting this for a long time. I hope, if I understand correctly, that I will be able to see if I have an image that isn’t being used at all. If I added an image into a page or post, will it show it’s being used there? Or does it specifically have to be “attached”?
    I always want to see who uploaded it as well. I’m a clean freak and if there’s old images sitting in the library not being used, I want them gone.

    • Some of the things you want are already available in WordPress. If you browse to the WordPress media library and select Unattached, you’ll be able to see which images are not attached to anything.The Uploaded By and Uploaded To information is coming in WordPress 4.0. What I want is the ability to see every post that is using an image. Right now, I can only see the post the image is attached to. There is a disconnect between the two which is what I’m hoping will be solved with improvements to the way post relationships are handled .

  2. I can fully relate to the frustration about media management in WordPress.

    Why can’t an image be attached to multiple posts? Because there are functions that return the ID of the “parent” post/page, so they would have to be altered.
    However, it is not like something like this hasn’t been done before. A post can have multiple tags and categories, but an image can’t belong to multiple posts? Pffff…

    Thankfully there is this plugin, which comes in handy from time to time, though it doesn’t really solve the big problem:
    http://wordpress.org/plugins/unattach-and-re-attach-attachments/

  3. > Although you can view the parent post ID the image is attached to, you can’t locate each post the image is used on.

    Your post inspired me to create a plugin which does that.

    It adds a “Used In” column to the list view in Media Library, as well as to the attachment details modal.

    It can find posts that use the image (including any of its intermediate sizes) in post content, or as a featured image. Works with custom post types too.

  4. Technically there already is a many-to-many relationship between posts and media items (as far as Featured Images go), but it’s not something inherent to posts in general.

    The trouble is that while media library entries are technically posts, and do act like objects in certain contexts, they’re still largely treated as an analog for a static physical file with some metadata on top. This means that much of the UI is focused on making the file upload process easy and possible on-the-fly, and the metadata is minimized and when possible hidden.

    So, if we want to start treating media library entries more like objects with proper recognition of their many-to-many relationships with posts, I feel like there’d need to be a significant re-thinking of how they are treated in the WP Admin. Otherwise it’s either going to complicate the existing upload process (which would be bad for average users) or result in a disjointed and unintuitive process.

  5. Hi Jeff, Thanks for the article.

    Have you seen instances where the image details of an attachment that is created in the post not reflect updates to the metadata, say, caption and alt, performed through the media library?

    Is this the correct behavior such that the attachment to the post is particular and can retain its own, distinct metadata apart from the same attachment in the media library? Or is this a bug?

    Thanks again!

Newsletter

Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.