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
- Front-End Post Submission
- Use category base slug in posts’ permalink
- 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?
- Change the Slug of Post Type post to baseurl/post/%postname%
- Disallow Same Post Title
- Get title of post without using the_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
- How to control which category will be picked for the slug of a post?
- Edit a post from frontend. post_tags get saved, but not separated
- Change slug with custom field
- Determining Slug Before and After Edit
- Developing a secure front end posting form
- How can I edit a post from the frontend?
- 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:
- upload featured image from front end using wordpress add media button
- 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 do I get the slug of a custom taxonomy category of a post?
- How to intercept Post Title on Post-Save
- Testing for post title in ‘if/else’ statement returns no content
- get_post_field – Title without paragraph
- Frontend Post Excerpt field mapping
- Add Category name to Post Title (h1)
- How to add a custom field after wp post
- Sorting posts alphabetical that have single digits
- Frontend Post Form Validation
- How Can i Get 5 Recent Post Title With Corresponding Link?
- How to get posts by multiple post slugs? [duplicate]
- Define a name to the posts slug
- I want to show category in the post title , how can I do
- How to prevent WordPress from updating the modified time?
- Bulk update post slugs through database
- How to display following posts titles in separate div’s on a separate webpage
- Blog Posts not showing title
- Lose “Blog Archive” from page title
- How to Orderby Comments by post title?
- WordPress not opening posts with only numbers if permalink is post_name
- Redirection not working in this front end post submission form?
- How to have posts have a parent in permalink like site.com/blog/postname
- Automatically add date to the auto generation of post slug
- How to handle broken links created by permalink/slug changes?
- How to change the color theme per post?
- Visting slug for ‘post’ post type shows 404 not archive?
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Adding an image to a non existing post
- How to make a bilingual front-end post using the plugin WP User Frontend and Polylang or qTranslate?
- how do i add posts-page slug before posts slug in permalinks
- Change Post Status From Front End
- sql select for post_title and a term name
- 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
- Images inside post title
- Loop doesn’t show title of second post and posts thereafter
- Disable WordPress Archive Conflict Check
- How To capitalize The First Letter Of Every Word In The Post Title
- How to show show the Second page title in the page
- 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
- Blog post not showing title
- How can I remove the first two words and shorten get_the_title()
- Lock post editing to one user at a time – wp_check_post_lock
- Front end post submission form with duplicate type fields
- How do I include the category next to the title of a post?
- How to style archive post titles… but only those posts who have comments?
- my post slug gets really long and I can’t change it
- Why in my query is display two title?
- Image behind the post’s title
- Show custom post with custom categories with specific slug
- Change Post Title For Specific Category
- How to remove “» (title of post or page)”?
- Get featured image on hover of post title [closed]
- Microformats in a single post – layout conflict
- post type slug vs page slug
- Can i have more than one form for front end posting in one template [closed]
- How do I display the post_title with get_permalink?
- Post titles and thumbnails as links to custom post types?
- Get Users Post ID