Please tell me, – is there a code I can use to automatically copy the title of a post and rename the filename of that post’s featured image according to that title, putting dashes instead of spaces, removing special characters, and converting to lowercase, – basically the usual stuff that WordPress does to post names automatically… And all that at the moment that post is published..?
I got this answer on StackOverflow, but am not sure exactly as to how to implement it…
save_postto get the event when a post is saved
add_action( 'save_post', 'update_file_image_name' );
Then you can use the function
This will pass you the ID of the post in question
To get the full path to the image. From here, you’re just going to use that url by splitting and taking what you need to walk the directory, find the file, sanitize the string as you’d mentioned, and then return out when done.
Thank you in advance!
- The topic ‘Auto renaming of featured image filenames in WordPress posts..?’ is closed to new replies.