The add_attachment
action is called after the attachment has been named. If you only want to change the name of the attachment (and the slug), you don’t need to change the name of the file and can just replace the code inside rename_attachment
with a call to wp_update_post
.
add_action('add_attachment', 'rename_attacment');
function rename_attacment($post_ID){
$new_attachment_name = array(
'ID' => $post_ID,
'post_title' => $post_ID, // changes what you see
'post_name' => $post_ID // changes the slug to 89
);
wp_update_post($new_attachment_name);
}
Related Posts:
- upload featured image from front end using wordpress add media button
- Too many connections to server
- Removal of Media Gallery pictures
- How to get the last selected media alignment setting?
- unable to write to the database while uploading images
- Disable Media uploader to users
- WordPress Media URLs?
- Inserting Media on New Post But Hides Previous Uploads for Editor/Contributor
- What is the proper use of guid for images in wp_posts?
- Automatically attach image to post if they have the same title
- Send post id through ajax and get the post content back
- Display post x of y within category
- Force authors to Preview a post before publishing
- Redirect to another page using contact form 7? [closed]
- redirect to uploaded (wordpress) post after form submission from front-end
- Order posts alphabetically: how to set order=asc in mysql query?
- Remove Featured Image & All Media Uploaded to the Post
- Change all author links in Blog roll
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- Every second post different class in blog view
- Format latest/newest post differently
- is_page Funtion for Posts ?
- Post type no single page
- Get post meta retrieving wrong value
- Adding a user’s ID behind the tag ref link address
- The_excerpt() doesn’t parse – how to change that?
- How to only publish posts with image in it
- Uploading images in custom post form
- Isn’t the way posts are displayed very unefficient?
- Upload attachment from external site
- Add custom text automatically on each post
- How to check in functions.php if there is data in a WP_Query?
- restrict incrementation of post vies count when refreshing the page
- Display a mixed list of posts and media
- Defined function isn’t showed on page
- WordPress 302 Redirect to Random Product/Post/Page
- Getting Whitescreen when publishing a post [closed]
- Using system date format
- Get post by tag
- Add code to a specific post’s content
- Related Posts function not working
- the_content() Not Grabbing All Content
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- Related Posts: Changing Function For Posts Per Page
- How to get all inline images in post content? [duplicate]
- Query function not executed between element [closed]
- Optimize CPT-function with a loop
- saving/reading custom field value does not work – no value gets POSTed
- Inserting Media to WordPress Posts
- Same post appears in related Posts?
- Internal linking to posts permalink fail because of spaces and stripe at postname
- Have h2 tag not show up if there are no blog posts
- Convert all uploaded PNG files to PNG-8 format
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Making a wordpress page print friendly
- How to call WordPress First Image Post or else Attached Image or Default
- Help on conditional statement to accompany wp_insert_post function please?
- How to implement a WordPress comments function?
- How can I to add upload functionality outside of the admin area?
- How to add content above footer in posts from specific category
- Set Default Post as Parent Child (Nested) Relation
- Delete Post but retain image of post [WP REST API]
- I need to create “View Profile” and “Edit Profile” links by incorporating the Post Title/ID, but can’t seem to manage it
- Site/Post preview is not working on all social media
- Cannot create new posts or upload images using media manager
- how to show comments only author which send own posts in wordpress
- get category in list of posts // shortcode for custom related posts
- shortcode // get posts by ids
- How to put the author of the post in the comments?
- Check if almost 10 year old – working code is up to date
- Alt text attributes not showing over portfolio images
- How to add HTML into error message
- Getting image data from phone camera (MediaDevices.getUserMedia) into user post
- Find most used words in post titles
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- $post->post_content empty while all other properties are correct
- Function is printing twice – any suggestions?
- How to add a custom class attribute into code wrapper? [duplicate]
- Get post attachment with post id
- Remove pagination if search returns empty
- Remove HTML tags from all posts
- Set a post expiration and delete a post when expirate
- Post images are not displayed in media library
- How to upload 3 attachments to current post?
- I want to change the WordPress comments file
- Replace Tag Keyword With Link Within Post Content
- Excluding tag Link from html tags in Post content
- Save All Post Permalink From A Specific Category into a .txt file
- Allow users to post their videos to my wordpress website?
- Changing a users posts to drafts upon role change
- Why does media_handle_sideload upload to last month’s folder?
- AJAX load more posts not using correct category and repeating the same few posts
- How to Display Most View Post in the template file?
- Get post id outside loop : Notice: Trying to get property of non-object
- Connection dropped due to file size
- Function image_send_to_editor returns emty title tag
- Show post excerpt
- How do I apply a wordpress function to something with no ID inside an archive page?