Skip to content

Instantly share code, notes, and snippets.

@CarlosLongarela
Created March 16, 2017 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlosLongarela/a51f6e6f12c14b64eece6f5af084dad1 to your computer and use it in GitHub Desktop.
Save CarlosLongarela/a51f6e6f12c14b64eece6f5af084dad1 to your computer and use it in GitHub Desktop.
Función para renombrar los archivos subidos a la mediateca de WordPress
function dng_nombre_archivo( $filename, $filename_raw ) {
$info = pathinfo( $filename );
$nombre_arch = $info['filename'];
if ( ! empty( $info['extension'] ) ) {
$ext = $info['extension'];
} else {
$ext = '';
}
$nombre_archivo = str_replace( '_', '-', $nombre_arch );
$nombre_archivo = sanitize_title( $nombre_archivo );
$nombre_archivo = $nombre_archivo . '.' . $ext;
return $nombre_archivo;
}
add_filter( 'sanitize_file_name', 'dng_nombre_archivo', 10, 2 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment