Last active
September 22, 2022 09:58
-
-
Save felipeelia/90932cbf27162e354534b46e0fd4da9c to your computer and use it in GitHub Desktop.
WordPress: remove acentos e espaços de nomes de arquivos. Mais em http://felipeelia.com.br/wordpress-remover-acentos-e-espacos-de-nomes-de-arquivos/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Remove acentos e espaços dos arquivos no upload | |
function custom_sanitize_file_name ( $filename ) { | |
$filename = remove_accents( $filename ); | |
$filename = strtolower( $filename ); | |
$file_parts = pathinfo( $filename ); | |
$new_filename = sanitize_title( $file_parts['filename'] ); | |
if ( ! empty( $file_parts['extension'] ) ) { | |
$new_filename = $new_filename . '.' . $file_parts['extension']; | |
} | |
return $new_filename; | |
} | |
add_filter( 'sanitize_file_name', 'custom_sanitize_file_name' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment