I have attached several images to a post. When viewing the images in the theme, each image is linked to a larger version of itself. I would like to change this link to direct to a specific URL. However, when I change the URL under "Link URL" under attachment options, the link does not stick after clicking "Save All Changes". It always reverts to the link to the image itself.

Is there another way to create custom links on attached images?

Note: I'm not trying to alter the link TO the image, I'm trying to create a custom link href when the image is clicked.

1 Answer 1


You say you click the Save All Changes button. I think this means you are trying to edit the images via the Upload/Insert images button above the editor? It's confusing, but this is not the place to edit an individual image that you already inserted into the post. In the Gallery tab you can edit settings for the image in the shared Media browser, but not for already inserted images. You need to do that by clicking on the image and then clicking the first button that appears (showing an image). This will give you a slightly different editing window, with an Update button at the bottom.

If the rel attribute of the image link is set to attachment, _fix_attachment_links() will replace the link with permalinks to the attachment when you save the post. So make sure that when you edit the image link, you first click the "None" button to clear this value, or go to the Advanced Settings tab and edit Link Rel so it doesn't contain attachment.

  • I have not inserted any images into a post. I've merely "attached" an image to a post by uploading it to the post using the Upload/Insert "Add an Image" wizard. I've got code in my index.php and single.php that displays all attached images to a post just before the post content appears. I simply want to give the end user control over where links lead when these images are clicked.
    – Scott B
    Oct 19, 2010 at 14:13
  • @Scott: Ah, but I think attached images do not store any link information in the database (at least I could not find any in the postmeta table). This is probably only used when you insert the image in the editor. So since the URL is not saved, you always get the default permalink to the attachment. If you want to change this you have to capture and save the URL yourself.
    – Jan Fabry
    Oct 19, 2010 at 14:36
  • I agree. I've posted another question on how to hack into the gallery manager to add a hyperlink field to each image in the media directory.
    – Scott B
    Oct 19, 2010 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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