WordPress feature request: Attach image to post in media uploader


When you insert an image into a WordPress post using the media uploader, there are three options: none, file url, or post url. You can also enter a custom link. I want to see a fourth option to link the image to the post that we are inserting our image in.

None obviously removes links altogether. File url links the image to the source file. Post url links the image to the attachment page, as attachments are their own post type in WordPress. None of these options are very good if your image is a prominent part of your post and you want it to link to the post itself.

Let’s say you use a typical blog format and display full content on your blog or home page. You may include up to three or four paragraphs for each post before a read more link that goes to the singular post page. When someone is on your home page and wants to read the full post, a big feature image is a likely candidate to click on to view the full post, so we don’t want this image to link to the source file or attachment file.

We also don’t want it to not link, because the user may expect that it links to the full post view. It is common practice when showing excerpts, rather than full content, to link images to the singular post page. We want to mimic that functionality when viewing home and blog pages with full content and more links. Even if more links aren’t present, we still don’t want to send the user to the attachment or image source pages if they happen to click the feature image.

Currently, you can enter a custom url, and it is easy enough to grab the shortlink from the main post edit screen to do so, but I don’t think it’s good enough. This is a fairly common use case, and there should be a fourth button in the media uploader to link the image attachment to the post itself.

I’ve looked for ways to add this functionality myself, but haven’t been able to figure it out. If anyone knows how, I’d love to see it.

10 thoughts on “WordPress feature request: Attach image to post in media uploader

  1. In short Brian, I agree with what you’re saying! — I’m always fooled with ”Post URL” as you expect it to be the URL for the post you’re writing, except it isn’t! It has been talked about on WordPress Trac (#13544) and will hopefully make it in for either 3.2 or just when Media gets an overhaul (I got my fingers crossed for either!) I’d also quite like to see what you suggested too, maybe it could be my next challenge? 😉

    1. Nice link on trac Mark. I talked to Ryan Imel about this as well, and he helped me figure out where to look in WP to find the appropriate hook.

      Dumb me was looking in media.php, but not the one under wp-admin.

      Turns out, this is pretty easy to add the button if you hack core, but there isn’t a hook currently that would allow us to do it without the hack. Ryan may post a ticket to include a hook so plugins can add their own stuff.

      Thanks for chiming in!

      1. If we take WPCandy.com then it’s something you do for every post on the site, so you’re using it all the time, and have plenty of experience on the topic! 😛 I use it once in a blue moon!

        At the end of the day I’d probably much rather see what you described above (and in the image) over adding a hook for plugins to use; but that will always be my personal preference!

    1. really think it shouldn’t be that hard to have a custom link on gallery items. there are several workarounds but im hoping this will be implemented in a future version of WordPress

    2. Thanks for the note Sebastian. I ran across that article when I was looking for my answer. It’s not quite what I had in mind though. I’d love a button that easily provides a link to the parent post, or at least the hook for a plugin to add it.

      I appreciate you stopping by!

  2. I haven’t really experienced a problem with this yet, but then again I don’t usually link an inserted image back to the post that it is located on.

    Having thought about it though, logically the “Post URL” button would add the URL of the post where the image will be added, and I think it probably should be corrected to say “Image Post URL” or something similar.

    I think this should be changed within the WP code rather than adding a hook for plugin developers to choose what they want the button to do.

Leave a Reply