Make WordPress Core

Opened 10 years ago

Closed 2 months ago

#1914 closed enhancement (fixed)

Permalinks for unattached uploads/attachments

Reported by: dlhau@… Owned by: pento
Milestone: 4.4 Priority: normal
Severity: normal Version: 1.6
Component: Permalinks Keywords: has-patch needs-unit-tests
Focuses: Cc:


Currently attachement links are in the form:


Would look much neater if these matched the permalinks of regular posts (depending on what it is configured to) eg:


Attachments (4)

attachment-permalinks.diff (3.2 KB) - added by MikeNGarrett 2 years ago.
Attachment Permalinks diff
1914.diff (475 bytes) - added by SergeyBiryukov 15 months ago.
1914.2.diff (1.9 KB) - added by wonderboymusic 2 months ago.
1914.3.diff (2.6 KB) - added by wonderboymusic 2 months ago.

Download all attachments as: .zip

Change History (27)

#1 @skeltoac
10 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Attachment permalinks are in the form [parent permalink]/[attachment slug]. There is not an intermediate attachment permalink style. What is an attachment without something to attach to?

It has not been decided what to do with orphaned attachments, although I think we should drop and unlink.

#2 @anonymous
9 years ago

  • Milestone 2.0 deleted

Milestone 2.0 deleted

#3 @Viper007Bond
4 years ago

  • Component changed from Administration to Permalinks
  • Keywords needs-patch added
  • Milestone set to Future Release
  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Summary changed from Attachement Permalinks to Permalinks for unattached uploads/attachments
  • Type changed from defect (bug) to enhancement

Re-opening this guy.

If media is uploaded using Media -> Add New, it doesn't get a permalink because it doesn't have a post.

I'd like to resuggest the idea proposed in the original post be reconsidered. Query strings are ugly. :)

Version 0, edited 4 years ago by Viper007Bond (next)

#4 @johnbillion
4 years ago

  • Cc johnbillion@… added

#5 @Hekos
4 years ago

  • Cc marko@… added

#6 @dd32
3 years ago

Currently http://example.com/attachment-slug-name/ will work for Attachments not attached to any posts, but we don't generate links using that format.

2 years ago

Attachment Permalinks diff

#7 @MikeNGarrett
2 years ago

Attached a patch here to enable this functionality. I'd love to get this request closed up since it's the oldest ticket in trac.

#8 @SergeyBiryukov
15 months ago

#29426 was marked as a duplicate.

#9 follow-up: @keketovic
15 months ago

  • Keywords 2nd-opinion dev-feedback added

Rather shame to see this as "won't fix". It just shows your general attitude to understanding of what permanent (and pretty) URLs should look like for the whole Wordpress, not just part of it, because some of the attachments are "orphans".

BTW, as a temporary fix I have reattached these orphans to the parent posts, so Wordpress now actually works instead of showing ugly URLs.

If prepending general "attachment/" part is not the solution to this and you don't offer any other suggestions than nothing is. I find the developers in this thread somehow pathetic in their stance towards this simple (and moreover logical - permalinks structure is set up after all!) request.

BTW, easy patch to fix this was uploaded exactly 12 months ago and nobody paid attention. That says something, doesn't it?

#10 @SergeyBiryukov
15 months ago

Per comment:8, we should probably just leverage the existing format in get_attachment_link() instead of introducing new rewrite rules.

#11 in reply to: ↑ 9 @helen
15 months ago

  • Keywords has-patch added; needs-patch 2nd-opinion removed

Replying to keketovic:

Rather shame to see this as "won't fix".

I find the developers in this thread somehow pathetic in their stance towards this simple (and moreover logical - permalinks structure is set up after all!) request.

This ticket is open. A lot of things change in 9 years. Let's all stay away from attacks, please.

We de-emphasize the attachment relationship in some ways now. I would agree that this is worth revisiting in that light. "Attachment" doesn't really seem like the right way to refer to a media item when it's not attached, though. We don't call it the "Attachment Library".

#13 @Drivingralle
13 months ago

I applied the two patches.
For the obvious case to query a single attachment page it works fine.

Are there special cases that I can test?

#14 in reply to: ↑ 12 @MikeNGarrett
13 months ago

  • Keywords needs-testing added

Replying to SergeyBiryukov:

1914.diff implements comment:10.

I tested all the changes from this patch (not including my patch for added rewrite rules) and it looks good.
I tested a number of different permalink settings. I think this is ready to go.

#15 @SergeyBiryukov
3 months ago

#33664 was marked as a duplicate.

#16 @SergeyBiryukov
3 months ago

  • Keywords needs-unit-tests added; dev-feedback needs-testing removed
  • Milestone changed from Future Release to 4.4

#17 @swissspidy
3 months ago

  • Keywords needs-refresh added

1914.diff only solves half of the problems:

  • The ugly permalink is still shown at some places, like in the media list table and when editing the media item
  • Doesn't work in every scenario. For example, when a media item is attached to some post that is from an old post type (not registered anymore, just lying in the database), the ugly permalink is used. There's no redirect to the pretty permalink.

#18 @wonderboymusic
2 months ago

  • Keywords needs-refresh removed

1914.2.diff accomplishes the goals of comment:17

#19 @wonderboymusic
2 months ago

1914.3.diff resets some flags after posts are queried to break the collision with pages, makes unit tests pass

#20 @wonderboymusic
2 months ago

  • Owner set to SergeyBiryukov
  • Status changed from reopened to assigned

#21 @wonderboymusic
2 months ago

  • Owner changed from SergeyBiryukov to pento

This ticket was mentioned in Slack in #core by wonderboymusic. View the logs.

2 months ago

#23 @pento
2 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34690:

Permalinks: Add pretty permalinks for unattached attachments.

Previously, unattached attachments would have unsightly /?attachment_id=1 URLs. As we've moved away from attachments being specifically attached to posts, instead being Media items, this has made the unattached URLs a more common occurrence.

We can breath easy once more, knowing that the world is a little bit safer from the horror of unnecessarily ugly URLs.

Props SergeyBiryukov, wonderboymusic, pento.

Fixes #1914.

Note: See TracTickets for help on using tickets.