Ocean90,
The link you added is broken. I've attached a image of the field that is causing the problem. I am unable to update this to point to anything but the default. I'm trying to get these to point to video posted on Vimeo, which will open in a lightbox on the site. If I remember correctly, you used to be able to do this without any problem.

This is a bug, why isnt it coming out with the next release? Its obviously been a bug for 8 plus months. When someone enters something into a field and clicks save changes, it should save all the changes. Is my request off base?

No intention to bring any confusion in here as it seems the patch is on its good way to some future release. However there is a wp-admin-only_no-plugin workaround, or at least it works for me.

before inserting the the image to your post press the None button right bellow the Link URL text input area.

then just press Insert into post button as you do usually

save your post

now get straight back to edit the picture's properties with Edit Image icon again

type your desired URL and just save the settings with Update

finally save your post and voila! :)

Notes:

If you prefer to avoid the Edit Image properties window loading and get all of it slightly quicker, you could use the common TinyURL text URL tool instead at the point d. and adopt the rest points accordingly.

It works for inserted galleries too, you just have to do this with each single pic.

I just loaded the plugin and now I can save the external website URL in the field, but when I update and view the gallery on the regular page, the URL show up as the address for the uploaded file instead of the website I want the image to link to... If I go back to the gallery settings again the URL shows up correctly. Any ideas on fixing this? What is happening?

Is this plugin compatible with WordPress 3.2.1? It would also be better is this wasn't a plugin but the actual WordPress PHP file just got fixed.

Without a plugin:
In a regular installation the "none" & "post URL" buttons of the gallery don't work. They display the correct address and look like they would work but nothing saves. So the URL link in the field always end up as the "File URL". Even if you click on a button then save the settings, and then update the gallery, the URL always goes back to the "File URL".

After loading the plugin/fix:
If we load the plugin we get the ability to save URL addresses but no matter what we do, the address of the URL on the real page (live website) shows up as the "File URL". When we go back to the gallery settings we can see the URL, we want an image to go to, has saved properly, but it doesn't link to the address on the live website.

*We have a plugin that helps us save a URL address, we just need someone to get the address to link up properly, so we can change the "File URL" to another URL. Please help us.

I copied the code below into a new file called save-custom-link-url.php and put it in a folder called save-custom-link-url in the plugins folder of wp-content and uploaded it to my server. The I just activated the file.

Now I can save the URL I want I just need someone to help me get the saved URL working on the live webpage... When I click on the image it just takes me to the image and not the URL.

Almost there...

If anyone can see anything stopping the saved URL from becoming the link I would love to find out what it is. I will make a tutorial telling everyone how to fix this problem as well. And I hope someone at WordPress reads this and helps. I've only been running 2 WordPress sites for just over a month. Well almost 2 months now but I still have a lot to learn.

I noticed one thing when inspecting the input field of the "edit gallery area" where we type in the Link URL (show -> single image settings area). The "value" tag of the field changes but the "name" tag is staying the same (<input type="text" class="text urlfield" name="attachments[1957][url]" value="​http://a4jp.com/gallery-3dcgi/">). Maybe that is where the problem is. How do I get the name tag to clear when I save my URL, or does something else need to change to fix the problem?

The link is 'saved' to the editor, but then reverts when 'Update' is clicked.

The workaround is to remove: rel="attachment wp-att-999" from the <a href ="link to external" rel="attachment wp-att-999">.
Hence, the bug is probably being caused by rel="attachment wp-att-999 being improperly inserted in the <a href> tag when trying to link to an externalI (non-image attachment) URL.

This isn't limited to external URLs for me on any site running 3.3.1 (and probably earlier).
Any URL inserted through the insert image dialog gets rewritten to link to the attachment page, even if you edit it in the html view.

I don't think the place to fix this bug is in media.php, unless it's to stop the rel="attachment" attribute getting added in the first place, and I can't see an obvious way to decide when and when not to add that attribute.

So the other way to attack it is via the _fix_attachment_links( ) function in /wp-admin/includes/post.php.

Here's the clue: If you revert this function to the one in wordpress 2.8 release the correct behaviour returns.

The change that triggers the error looks like it's the addition of the preg_replace_callback

If I follow this correctly it's completely rewriting the href attribute by calling into get_attachment_link() in the callback function.
So any link with rel="attachment" and a parsable ID in that rel anywhere in the post content will get destroyed by this every time a post is saved.

Traced this back to #1870. It seems that the problem for which _fix_attachment_links() was introduced doesn't exist any more.

Did some quick testing and don't see any problems with attachment links and URLs to attached files that would require them to be fixed/rewritten after the post is saved. Seems we can safely stop replacing the URLs.

There is also another part to _fix_attachment_links(). It attaches orphaned attachments when they are used in a post (if the "wp-att-###" bit is present). This is useful for files that were uploaded directly from the Media -> Add New screen. However we are also doing something similar while inserting a file into the editor (in media.php), so not sure if repeating it is needed.

Overall removing _fix_attachment_links() seems the proper solution. This also improves performance while saving a post.

It has taken 7 months but I almost have a perfect fix for the native gallery bug. I just need to fix the code so it doesn't end up in a Colorbox or Lightbox like on my test site. You can see the working gallery links to pages in my site at the bottom of the gallery test page. It's the same page I was working on 7 months ago but the pages show up in Colorbox popups at the moment. ​http://a4jp.com/gallery777

I'm sure there are a lot of people here that could have fixed this problem in a night though :o Sorry it took me so long I had to learn a lot. I just need to fix the Colorbox problem now.

Can someone also help me make links to sort post data on the search.PHP page?

Is it best to make the code into a plugin after everything is working or just post it here???

azaozz and I chatted in IRC. We cannot lose _fix_attachment_links() entirely because it changes attachment links from attachment_id=xxx to the permalink version when the post is published. It could probably be reworked to run only when changing from draft to publish however. As it is now it does an extra save every time a post with attachment links is saved.

Proposal: Call _fix_attachment_links in _transition_post_status() when transitioning from not published to published. Only rewrite attachment links of the form attachment_id=xxx. Drop the orphan checking code. Only re-save the post if a link was rewritten.

When clicking the "Insert into Post" button in the gallery popup (while creating the content that is inserted).

Tested several ways to make that more transparent, _fix_attachment_links() is a "filter", perhaps better run on the content right before saving published or updated post. If run on "transition_post_status" it starts a loop (as it calls insert_post too). That would also prevent running all the hooks for saving a post for second or third time.

When clicking the "Insert into Post" button in the gallery popup (while creating the content that is inserted).

I meant in the code.

Tested several ways to make that more transparent, _fix_attachment_links() is a "filter", perhaps better run on the content right before saving published or updated post. If run on "transition_post_status" it starts a loop (as it calls insert_post too). That would also prevent running all the hooks for saving a post for second or third time.

Yes, but to make that filtering transparent it would be better to filter post_content before saving in the DB rather than re-saving the post again. Patch is mostly ready, will add it after some testing.

Looks good overall. I think $site_url could go after the checks that determine if attachment_id links are present. I hope "remove the protocol" is robust enough, I think we usually do preg_replace() for that. I'll do some testing.

In 13429-5.patch moved the $site_url after that check and made the removal of the protocol from $site_url a bit more robust (trying to avoid preg_replace() and use substr() + strpos(), but the difference for such short string is probably negligible).

The links aren't updated upon publish. You must save one more time after the initial publish to get updated links. This is because the wp_insert_data action is fired prior to DB update so the get_attachment_link() call in _fix_attachment_links() doesn't have access to the new post_name value.

Ugh, was trying to find out why it was re-saving posts, thanks for spotting that. Updated the patch, it re-saves only published posts and only if there's a change (removed the slash matching from the regex as we pull the post from the DB, so it's not slashed).

Thank you, SergeyBiryukov, for the plugin that allows custom URLs to be saved for images.

Currently on version 3.4.1 and still no fix to the gallery problem, however. The problem, I take it, is that there is no option under "Gallery Settings" to link to anything other than file or attachment page?

I worked around this by creating the same div container that the gallery creates, and inserting into it the files individually in thumbnail size. Then I added the class to the thumbnails that the gallery would have. This worked perfectly to create a "gallery" that looks exactly like the actual galleries. However, it was a lot more hassle than inserting a gallery simply would have been, and I would not want to have to do it for a large gallery (mine was only 6 images).