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”.
Related Posts:
- Make attachment pages require a base url
- Media/attachment urls don’t redirect with fake URL structure
- Code snippet to add filter pre_post_link to change Media URL (post_type attachment permalink/slug)
- Is it possible to get a page link from its slug?
- WordPress slug issue with non-latin characters
- Removing the redirect after changing a page’s slug
- Must slugs be unique?
- How does wordpress keep track of post id when post id is not used in permalinks?
- Change slug on post creation
- Prevent WordPress from abbreviating-long-slugs…-in-the-admin
- Post type child of another post type
- How to prevent apostrophes and quotes from appearing in permalinks?
- Is there a user-facing interface to edit an attachment’s permalink?
- Why don’t WordPress post slugs allow accents?
- Is It A Good Idea To Change Author Slug (user_nicename field) Directly In MySQL DB?
- When creating a WordPress page, a “-2” suffix is added to new pages’ permalinks
- How to i18n slugs for templates?
- Remove parent slug for child pages
- Post being redirected to attachment post
- How to Remove Slug From Database?
- How to make draft posts or posts in review accessible via full url / slug?
- Remove parent slug for child pages
- Replace WordPress %postname% suffix with %postid%?
- Limiting the number of words or characters in the slug/permalink
- Media items hogging pretty permalinks
- Is it possible to list post attachments in a sub URL endpoint with a dedicated template?
- Gutenberg Editor: dynamicaly change slug field with an ACF field
- How to edit the slug/permalink in Gutenberg?
- Attachment page 404 not found when image is attached to post
- Image Attachment Url Rewrite
- How to replace “wp-content/blogs.dir” with “media” for attachment permalinks?
- Adding File Extensions to Attachment Page Permalinks
- How to generate random numeric slugs for a custom post type?
- Custom attachment permalink structure [closed]
- Filter string like a slug
- How can I add a page’s ID to its permalink using WP_Rewrite?
- How to modify the slug for the default wp posts without affecting other posttypes?
- Auto-create a pretty permalink for a bunch of posts
- Attachment Page Permalink/URL Rewrite Issue. How to change the actual rewriting?
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- Get new WordPress slug from old wordpress slug
- Non latin post slug truncate
- filtering special chars from post slug
- Editing URL character replacement
- Share same Slug for a Custom Post Type and 2 Taxonomies
- force permalink slug for page vs post_type slug parent
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- get_permalink returning site home url instead of the url of slug being passed
- Edit page slug after save, cause 404 by linked pages
- Pre-populate Slug / Permalink with URL
- Slugs Disappeared Leaving 404s – Quick way to repopulate?
- Custom permalinks in WordPress
- wordpress how to replace url /bar with foo/bar for custom post type
- Suddenly new posts have the default permalink instead of the post name
- How to Custom Edit Post Title & Permalink Slug?
- Remove “attachment/” from the URL of attachment pages
- I’ve removed my /author/ slug but it clashes with new and existing pages. Any fixes?
- Bulk append URL (add word to slug)
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- Post Title to link to a PDF
- How do i get post thumbnail using attachment code
- Page content doesn’t display when published but does when previewed as draft?
- Help me fix these crazy attachment page URLs (rewrite?)
- Is there a way to show attachment IDs on the attachment info screen?
- Remove international characters from slug – Almost done – Bit help
- How to create posts or pages with the names in wordpress?
- How do I rewrite attachment urls when permalink structure contains %category%?
- How to remove slug from front page?
- Gutenberg Editor: dynamically edit slug field based on ACF field
- How do I structure my permalinks in WordPress?
- Double Slash After Media Path (uploads//)
- New posts link to old posts (random)
- Modify post slug before saving
- Does wordpress take care of slug collisions?
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- How to prevent wordpress from lowering Capitalized letters
- WordPress Attachment Page URL Rewrite!
- WordPress slug confusion
- How do I use the same Tag slug for different Tags?
- WordPress image title attribute becomes permalink? [duplicate]
- How to create a standard WP Page that has the same url as an archive
- permalink not showing correctly using wp_insert_post and post_name
- 404 error on published page with specific permalink
- How to allow different authors to use same post slug?
- Problem with permalinks
- Allowing slash in slug/permalinks
- Author permalink
- Force/Limit the post/page slug to accept only url friendly characters
- Removing or hiding slug/permalink from htaccess
- Automatically remove repeated words in slug
- Keep wordpress from modifying my permalinks
- Is there a way to remove the option to modify the Slug in post.php
- Create a permalink for a post’s attachments
- How can i edit all posts slug in bulk keeping WP native redirect?
- Display a custom slug in URL depending on user variable
- Post/page without slug
- Different template fallback when changing permalinks
- UI does not show correct Slug after modified using save_post action
- Pages resolve at different URLs (different capitalizations)
- WordPress not remembering old slugs for pages