Rename name image upload
-
Hi, I need to change/renaming the image when uploading.
I’m using the code below and it works perfectly on the wordpress backend, however, it’s not working on the WC Vendors frontend form, can you help me solve this please.Código:
/*Renaming attachment files to the post title*/ function file_renamer( $filename ) { $info = pathinfo( $filename ); $ext = empty( $info['extension'] ) ? '' : '.' . $info['extension']; $name = basename( $filename, $ext ); if( $post_id = array_key_exists("post_id", $_POST) ? $_POST["post_id"] : null) { if($post = get_post($post_id)) { return $post->post_title . $ext; } } $my_image_title = $post; $file['name'] = $my_image_title . - uniqid() . $ext; // uniqid method // $file['name'] = md5($name) . $ext; // md5 method // $file['name'] = base64_encode($name) . $ext; // base64 method return $filename; } add_filter( 'sanitize_file_name', 'file_renamer', 10, 1 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Rename name image upload’ is closed to new replies.