I know there is many solutions how to rename attachment while upload files to postid. I got correct solutions that really works fine is: https://wordpress.stackexchange.com/a/30767/86517 (I’m new and I can’t comments there. So I ask this question.)
The code is:
add_action('add_attachment', 'rename_attacment');
function rename_attacment($post_ID){
$post = get_post($post_ID);
$file = get_attached_file($post_ID);
$path = pathinfo($file);
//dirname = File Path
//basename = Filename.Extension
//extension = Extension
//filename = Filename
$newfilename = "NEW FILE NAME HERE";
$newfile = $path['dirname']."https://wordpress.stackexchange.com/".$newfilename.".".$path['extension'];
rename($file, $newfile);
update_attached_file( $post_ID, $newfile );
}
But Problem is, I want this changes only for 3 custom post types.
Currently my site have 6 custom post type. So Only 3 custom post type need this. There is any way to allow to run this function only for those custom post type?
Thanks