Make WordPress Core

Opened 8 years ago

Closed 6 years ago

#6437 closed defect (bug) (fixed)

Image/Page naming collisions

Reported by: SpencerLavery Owned by: ryan
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.7.1
Component: Permalinks Keywords: has-patch needs-testing
Focuses: Cc:


The ability to change a media file's permalink 'slug' would be awesome. Currently it appears to use the meta data (EXIF?) from the photo and not the 'title' that you input. If it worked off of the 'title' that would be an improvement, but being able to fully customise it would be very handy.

Attachments (3)

9437.diff (1.6 KB) - added by Denis-de-Bernardy 6 years ago.
9437.2.diff (1.6 KB) - added by Denis-de-Bernardy 6 years ago.
6437.diff (1.8 KB) - added by Denis-de-Bernardy 6 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 follow-up: @kjellkk8 years ago

  • Type changed from enhancement to defect

I think this should be considered a Bug. Since it actually means that if you have a page with the same slug, it will be "overriden" by media files.

The slug for media files/pages should be treated like other slugs, so that you can not have conflicting slugs.

comment:2 @kjellkk8 years ago

oh - and forgot to say, besides editing the MySql tables directly - deleting the file and re-uploading with a new filename is the only way to fix it if.
That is if I want to have the page with the same slug showing properly.

comment:3 @kjellkk8 years ago

on third thought. This is a bug most definitely, shouldn't the media pages come up as

www.site.com/pagename/attachment/medianame ?

Those links don't work with the RC2 I installed. Ie they exist as without /attachment/ and won't work.

comment:4 @SpencerLavery8 years ago

  • Severity changed from normal to major

I wasn't aware that they had a higher priority than page slugs - that does seem odd. They don't seem to slot into the URL Rewrite structure very well at all currently. You're correct in suggesting that they should have their own seperate URL base such as "attachment" - I would personally prefer "media" but I'm sure it should be changeable. I would prefer it as:


Losing the page/post name from the URL entirely, as with the old-style file uploads (typically "/wp-content/uploads/"). Because we should be able to add a media file to multiple pages and posts and have each media file retain its own orginal permalink for SEO purposes and to keep comments consistent.

An aside- how does the media file's permalink overwrite a Page's permalink with a default permalink structure? Surely the post-name in the media file's permalink shouldn't prevent that?

comment:5 @SpencerLavery8 years ago

  • Severity changed from major to normal

Didn't mean to do that.

comment:6 @janbrasna7 years ago

  • Cc janbrasna added
  • Component changed from General to Gallery
  • Keywords attachment gallery added
  • Milestone changed from 2.9 to 2.8
  • Owner anonymous deleted

The slug is indeed generated from the uploaded file name, only sanitized.

I think we should be able to generate own slug if needed (as well as set other things like comments/pings_status, see #8177 etc.).

Some other described symptoms are already fixed in 2.7, e.g. the current attachment permalink is:


and shouldn't normally collide with anything (as long as you keep away from using some comment-page- or page- and similar as filenames).

Because we should be able to add a media file to multiple pages and posts and have each media file retain its own orginal permalink for SEO purposes and to keep comments consistent.

If you add the same attachment to multiple posts, it links to the original URL, so there's always only one incarnation of the attachment (as this is the way to collect all the comments under the attachment and to avoid duplicate content).

comment:7 in reply to: ↑ 1 @anmari7 years ago

  • Cc anmari added
  • Component changed from Gallery to Permalinks
  • Keywords menu added; gallery removed
  • Owner set to ryan
  • Summary changed from Media Library file permalink to Media Library file permalink page slug
  • Version changed from 2.5 to 2.7

Replying to kjellkk:

Since it actually means that if you have a page with the same slug, it will be "overriden" by media files.

I think this is exactly what happened to a client of mine. She could edit a sub page, but whenever she viewed it, then media.php came up with what appeared to be images with the slug name in the image somewhere. She could not get her edits to show up. I eventually figured out more or less what was happening and changed the page slug names, since changing the image titles did not seem to make a difference. I wrote the situation up in more detail here: http://webdesign.anmari.com/submenu-page-slug-attached-media-confusion/

comment:8 @truthmedia6 years ago

  • Cc truthmedia added
  • Keywords naming collision added
  • Summary changed from Media Library file permalink page slug to Image/Page naming collisions
  • Version changed from 2.7 to 2.7.1

Still experiencing this on WP 2.7.1.

Steps to duplicate:
On a vanilla WP install with the URL rewriting enabled, attach an image called test.jpg to the About page. Then create a sub-page under About called "Test". When attempting to view /about/test/ you will see the image, rather than the "Test" page.

The same problem exists when uploading images directly to WordPress through the media library controls as opposed to attaching an image to a post. In this case, the image parent is set to '0' and the image test.jpg is viewable directly off the root of the site at /test/ and can override existing pages with the same name on the same level.

@Denis-de-Bernardy6 years ago

comment:9 @Denis-de-Bernardy6 years ago

  • Keywords has-patch needs-testing added; menu media attachment slug permalink naming collision removed

please give the attached patch a shot in the latest trunk

comment:10 @ryan6 years ago

$sql should be $check_sql?

@Denis-de-Bernardy6 years ago

comment:11 @Denis-de-Bernardy6 years ago

very true. updated diff attached.

@Denis-de-Bernardy6 years ago

comment:12 @Denis-de-Bernardy6 years ago

6437.diff uses a slightly different approach. It fixes the potential issue with attachments and pages rather that only pages. And it would allow other hierarchical types added by plugins to be processed as well if needed.

comment:14 @ryan6 years ago

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

(In [11125]) Make post slugs unique across all hierarhical post types. Props Denis-de-Bernardy. fixes #6437

Note: See TracTickets for help on using tickets.