Wordpress - Stop WordPress from reserving slugs for media items?

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".


You may hook wp_unique_post_slug() and append some string to the original slug if the post is an attachment type. The original slug based on post title will remain free.

UPDATED after Rachel Baker's comment: original slug suffix is some random string. It does not guarantee uniqueness but may be enough for simple use cases.

add_filter( 'wp_unique_post_slug', 'wpse17916_unique_post_slug', 10, 6 );
function wpse17916_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
  if ( 'attachment' == $post_type )
    $slug = $original_slug . uniqid( '-' );
  return $slug;
}