Stop WordPress from reserving slugs for media items?

I am experiencing some odd behavior, that apparently happens “out of the box” with WordPress.

If I upload a file through the media manager called: services.jpg; then go try to create a page with the permalink http://example.com/services/; The slug services-2 is given instead, because the attachment is already using that slug.

Visiting http://example.com/services/ loads the attachment page.

I have not enabled any plugins or added anything into functions.php to modify the rewrites for attachments.

Has anyone run into this before? Know where to start to disable this functionality?

4 s
4

Thank you for the response everyone. I played around with macemmek’s solution and I think it led me to an even better solution:

add_filter( 'wp_unique_post_slug_is_bad_attachment_slug', '__return_true' );

That is all that is needed. This will automatically ‘skip’ the default assigned slug on any attachment. So an attachment that might normally get the slug “services” will now get the slug “services-2”.

Leave a Comment