You can use sanitize_file_name
filter to rename file. put this code in active theme’s functions.php, this will rename image filename as postname if only get title
request. I have tested this code and it is working fine.
Post name : https://prnt.sc/q3thzw
Uploaded renamed image : https://prnt.sc/q3tib7
function make_filename_as_post_name($filename) {
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$name = basename($filename, $ext);
$new_name = $_REQUEST['title'];
if(!empty($new_name)){
# Replace space with dash
$new_name = preg_replace('/\s+/', '-', $new_name);
return $new_name . $ext;
}else{
return $name . $ext;
}
}
add_filter('sanitize_file_name', 'make_filename_as_post_name', 10);
let me know if this works for you!
Related Posts:
- Edit the post title from the frontend
- Auto update post title and slug when post status is changed
- How to change the case of all post titles to “Title Case”
- Where is the old post permalink slug stored?
- Apply the_title() filter in post & page title, but not in menu title
- Custom Post Types, slug, archive and SEO plugins
- Remove post title input from edit page
- How to automatically generate a unique random slug
- Post slugs and images cannot have same name?
- Set Post Title to Read-only and Disable Permalink Slug Editor in Gutenberg
- How to upload post thumbnail while wp_insert_post?
- Disallow Same Post Title
- Verify if tag is used on posts
- Publish pending article from front end with a button?
- Get names of authors who have edited a post
- Dynamically update post title in admin page
- Determining Slug Before and After Edit
- Developing a secure front end posting form
- Developing a secure front end post editing form
- How to show posts rank based on custom field value
- Post from front-end only by logged in users, form posts as “posted by:
- Post & edit a post from front end along with upload, dropdown, and other inputs
- How to update all post at once?
- Displaying Page Title on index.php
- generate unique slug while inserting post
- How to intercept Post Title on Post-Save
- Frontend Post Excerpt field mapping
- Add Category name to Post Title (h1)
- How to add a custom field after wp post
- Frontend Post Form Validation
- How Can i Get 5 Recent Post Title With Corresponding Link?
- How to prevent WordPress from updating the modified time?
- Blog Posts not showing title
- Redirection not working in this front end post submission form?
- How to have posts have a parent in permalink like site.com/blog/postname
- How to change the color theme per post?
- Adding an image to a non existing post
- how do i add posts-page slug before posts slug in permalinks
- WordPress is replacing double minus signs in Post Title, how to disable it?
- 404 error on default post type and default taxonomy fronted page
- How do I change the core post search algorithm? Where is it found/constructed?
- Is there a way to specify an extra class for a post or page with no title?
- How to get a post’s content? [closed]
- Add title for previous and next posts to Yoko Theme
- Loop doesn’t show title of second post and posts thereafter
- How to get links to the last N posts in a specific category?
- Create a list of posts with topic headdings
- Two Custom Post Types with Identical Articles Competing for the same Slug
- WordPress custom post type with folder structure in slug
- Front end post submission form with duplicate type fields
- How do I include the category next to the title of a post?
- Why in my query is display two title?
- Image behind the post’s title
- Show custom post with custom categories with specific slug
- How to remove “» (title of post or page)”?
- Get featured image on hover of post title [closed]
- Microformats in a single post – layout conflict
- How do I display the post_title with get_permalink?
- Get Users Post ID
- If post exists, make it a comment in existing post with same name?
- WordPress wp_editor to post and edit
- Change modified date to current date when title updated automatically
- How to select a category automatically based on a word in WordPress post title?
- how to show current date on post title which should be auto update in every day
- Adding Text after Post Title based on Category using IF Condition – But not for menu items
- How to merge the content of posts that have the same title?
- Add id attribute to h1 element of wordpress post
- Odd hyphen added at end of blog post
- Slug collision between page, taxonomy and custom post type
- My posts page is missing the page title
- Hiding title of selected post without plugins
- 2 Domains, Same Content, Different Titles?
- Post Category link is same with Page link
- My post permalinks are always the same
- Allow reader to reorder posts for themselves (oldest first)
- If I moved the location of my generic “posts” page, do I need to change the slugs for all of the individual posts?
- post_name is not stored until post is published… where should I store my slug until it goes live then?
- How can I choose and change a post title at random from an array when it is published?
- Post title to show all characters after having it limited for preview
- Post/Edit/Delete Post From Frontend… How?
- Add Image Before Posts Entry Title
- Send/Publish a Post front end
- prevent same wordpress post title
- Get post title by Alphabet
- Get post title of faulty link on 404 error page
- User driven content problems
- Is it possible to have different header style blog titles in different categories?
- retrieve post slug by post_tags taxonomy
- display only the title of the post into a certain category
- Stop Authors from submitting spam post
- Show all posts in category
- How do I show the post title if an advanced custom field hasn’t been used?
- Deleting first four characters from all Post Titles
- How remove “recent comments” title without modifying code? [closed]
- clicking on page title
- Title displaying multiple times
- Is there any point to using wp_unique_post_slug?
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- How to change Post title background size?
- How to link Post Title to uploaded file?