Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '10 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 '10 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 '10 at 14:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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