Make WordPress Core

Opened 10 years ago

Closed 10 days 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 14 months ago.
1914.2.diff (1.9 KB) - added by wonderboymusic 11 days ago.
1914.3.diff (2.6 KB) - added by wonderboymusic 11 days ago.

Download all attachments as: .zip

Change History (27)

comment:1 @skeltoac10 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.

comment:2 @anonymous9 years ago

  • Milestone 2.0 deleted

Milestone 2.0 deleted

comment:3 @Viper007Bond4 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)

comment:4 @johnbillion4 years ago

  • Cc johnbillion@… added

comment:5 @Hekos4 years ago

  • Cc marko@… added

comment:6 @dd323 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.

@MikeNGarrett2 years ago

Attachment Permalinks diff

comment:7 @MikeNGarrett2 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.

comment:8 @SergeyBiryukov14 months ago

#29426 was marked as a duplicate.

comment:9 follow-up: @keketovic14 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?

comment:10 @SergeyBiryukov14 months ago

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

comment:11 in reply to: ↑ 9 @helen14 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".

@SergeyBiryukov14 months ago

comment:13 @Drivingralle11 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?

comment:14 in reply to: ↑ 12 @MikeNGarrett11 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.

comment:15 @SergeyBiryukov5 weeks ago

#33664 was marked as a duplicate.

comment:16 @SergeyBiryukov5 weeks ago

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

comment:17 @swissspidy5 weeks 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.

@wonderboymusic11 days ago

comment:18 @wonderboymusic11 days ago

  • Keywords needs-refresh removed

1914.2.diff accomplishes the goals of comment:17

@wonderboymusic11 days ago

comment:19 @wonderboymusic11 days ago

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

comment:20 @wonderboymusic11 days ago

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

comment:21 @wonderboymusic11 days ago

  • Owner changed from SergeyBiryukov to pento

comment:22 @slackbot11 days ago

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

comment:23 @pento10 days 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.