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?
- How do you create a “virtual” page in WordPress
- Multiple endpoints to same page
- Preserving $_GET parameter while using custom Rewrite Rule
- Getting add_rewrite_rule and add_rewrite_tag to work
- Why did installing wordpress in url root jack up underlying WP sites?
- Passing & Reading URL Parameters with URL re-writing
- Prevent WordPress from automatically correcting URLs
- add_rewrite_rule and pagination issue
- Display content according to current URL
- copy attachments to another post type and change attachment url
- External/non-WP rewrite rule without QSA
- How to do Basic URL Rewrite Without Redirecting
- Rewrite rules for custom post type slug
- How does WordPress determine if a paged query var is too high?
- Using category slug in add_rewrite rule
- Pass a comment id through url and append the comment post’s slug in the url
- How to change the main site url on a multisite installation (network)?
- Problem with add_rewrite_rule
- optimize wordpress rewrite rule regex
- How to catch Rewrite rules then display a specific post?
- Change custom post type slug from plugin options
- Generating a Rewrite Rule for sSecific Post-Requests from a Submitted Form?
- URL Rewriting for PHP script on an image URL
- Custom rewrite url category
- How to rewrite wordpress urls with index.php in them
- Rewrite URL based on home_url
- Replace term archives with static pages
- IIRF + IIS 6 + WordPress does not return 404 error
- Is it possible to set the same base for categories and tags?
- Adding a rewrite rule to page that has no fixed variables and pagination
- Flush rewrite rules on option update with Settings API
- Integer based rewrite isn’t recognized for value of 1
- wordpress url correction
- Custom Post Type Advanced Slug
- add_rewrite_tag works for some parameters but does not for others
- Rewrite specific action url
- Rewrite rule shows 404 page
- Exclude subfolder in WordPress permalink
- wordpress path generation from rewrite rule
- A different permalink structure for different categories
- Rewrite rule for custom permalink structure
- Help with .htaccess setup to hide WordPress Directory
- Ugly URLs when there’s pagination
- Hide wordpress source code
- Custom rewrite from URL to URL using slug
- Properly maintaining an old rewrite structure
- hierarchical taxonomy in permalinks? using same slug
- Using 2 URL’s for WordPress
- Rewriting WordPress URLs
- How can i maintain permalink structure and avoid a 404 error when loading external content?
- How to rename the WordPress wp-login.php running on IIS6?
- Rewrite rule to simulate page hierarchy results in 404
- Custom post type Premalinks main page and details page
- add_rewrite_rule not working with custom variables