Use the add_attachment hook to update the slug after the attachment has been inserted:
function wpse_182454_attachment_id_as_slug( $post_id ) {
if ( get_post_field( 'post_name', $post_id ) != $post_id ) {
wp_update_post(
array(
'ID' => $post_id,
'post_name' => ( string ) $post_id,
)
);
}
}
add_action( 'add_attachment', 'wpse_182454_attachment_id_as_slug' );
Related Posts:
- Change the “page” slug in pagination
- Change author base slug for different roles
- Using custom/dynamic “slug” for a page
- Display posts with author in the url with custom post types
- How to seamlessly redirect between different archive and singular slugs?
- How to add dot(“.”) in post slug
- How to change default page slug?
- Handle category name URL rewrite before different post type slugs
- How to change ?lang=cn into /cn/
- custom htaccess rewrite rule for page
- Change Attachment Post URLs to File URLs
- Change default URL of image attachment
- Why is there /index.php/ in all my links? How do I remove it?
- Multiple Permalinks for Same Post
- Adding more pages to author pages
- Using Blog Parent Slug on Blog Posts Only
- Load a template page based on part of slug in wordpress
- Removing “category” from URLs then “add_endpoint()” won’t work…
- How to remove parent section from attachment URL?
- Access files at new location using old file paths
- Adding special characters to slug?
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- Preserve old website URL structure after migrating to WordPress
- Attachment page gives 404 if user not logged
- How to change the Author Slug from Username to Nickname and deal with Special Characters
- How to change custom post type slug
- Disable WordPress from changing URL slug when post is published
- Using URL rewrite to add custom URL for custom post type
- One off rewrite for single post-type slug (show normal page with same URL instead)
- custom url – add attachment’s id or name after post
- Can’t use a specific custom URL (slug)?
- How to transform multiple parameter URL to clean URL
- Make the home page’s slug visible in the browser’s URL bar
- Trying to add array of paths to post permalink
- Changing the wordpress default search url to something like – …example.com/search?query=keyword
- How to add dot(“.”) in post slug
- WordPress is adding “category” word before my actual category name in url (and this is unsolicited)
- Change author base and slug in author link
- WordPress numeric (yearly) page names / disable yearly archives
- Post & Page with same slug
- How to add 2 variable rewrite rule?
- taxonomy term in URL slug won’t forward to the correct term for custom post like it does for default categories/normal posts
- Remove Page Slug from URL
- Needed to change slug to access page
- Pagination posts. Url format
- Change the slug ( url ) to a sequence number starting from 0 in the custom record type?
- Switch WordPress to non-absolute links? [closed]
- Rewrite Slug for CPT Archive Pages to Plural Name of Slug
- How to add custom rewrite rule to .htaccess?
- Problem with add_rewrite_rule and pagination (paged and page query_vars)
- Custom Permalinks for Blog Posts Only
- Detect page type by url (Archive, single, page, author,…)
- How to show the same content on multiple URLs?
- Using a page template without a page
- Overwrite rewrite-slug of built in post-type ‘post’
- Why does wordpress still strip my query var?
- When to call `add_rewrite_rule` for safety
- URL rewrites and pagination
- Rewrite rules goes away
- Rewrite Rule for Post “Subpage”, with pagination
- unexpected problem in url rewrite
- Need to make a php file inside theme accessible via url
- Remove child category from URL
- Rewrite loading custom template file but is_home() returns true, and there’s no 404
- Rewrite rule for admin-ajax.php
- Change WordPress comments url / word
- Cache issues with redis and nginx
- Rewrite WordPress Custom URL
- WordPress removes spaces in URL on pagination
- How to check current URL for endpoint in a template file?
- add_rewrite_rule not working for language specific characters
- Custom rewrite rule
- Add query string to url and display it as normal url part /folder/
- Is it possible to remove feeds from rewrites?
- Flush Rewrite Rules on init or rest_api_init?
- WordPress .htaccess – route other URLs to another app
- Rewrite URL – insert custom variables as a directory path
- URL endpoint with HTML
- How to properly rewrite url by custom var
- Change author slug and functionality
- Can’t add external rewrites
- Changing RSS feed URL structure
- Preserve Domain Alias
- Mobile version issue when domain forwarding with masking
- How to building pretty URLs to reflect category hierarchy?
- WordPress Rewrites – How can I pass a variable to Custom Post Type?
- Need to add rewrite rule that adds in additional information about the post to url
- add_rewrite_rule is redirecting instead of rewriting url
- Rewrite rules automatically for pages using specific template
- Add language prefix to permalinks
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Including taxonomy term before post type breaks top level pages
- Rewrites: .htaccess or wp_rewrite for bulk 301 changes?
- Custom Rewrite Rules
- Url rewrite with htaccess
- Add extra optional text to permalink e.g. “-with-*”
- How to change url of specific posts with name of a root page
- Error 404 wordpress redirecting URL
- Rewrite URL variable to custom path
- Own code on index.php wordpress theme file, help with the rewrite rules