WordPress filter hook · part of WordPress core

sanitize_file_name_chars

A WordPress core filter that 8 plugins also fire themselves, running on 1.1M+ sites between them.

“Filters the list of characters to remove from a filename.”

How to use sanitize_file_name_chars

It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'sanitize_file_name_chars', function( $special_chars, $filename_raw ) {
	// Change $special_chars here.
	return $special_chars;
}, 10, 2 );

Argument names come from MainWP Child's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

8 plugins that fire sanitize_file_name_chars

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. MainWP Child icon MainWP Child700,000+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ) class/class-mainwp-child-misc.php:588
  2. Photo Gallery, Sliders, Proofing and Themes icon Photo Gallery, Sliders, Proofing and Themes300,000+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $dirname_raw ) products/photocrati_nextgen/modules/legacy_compat/package.module.legacy_compat.php:2052
  3. Clearfy Cache icon Clearfy Cache40,000+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ) components/cyrlitera/includes/classes/class-configurate-cyrlitera.php:155
  4. Cyrlitera icon Cyrlitera40,000+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ) includes/classes/class-configurate-cyrlitera.php:155
  5. Backup and Staging by WP Time Capsule icon Backup and Staging by WP Time Capsule10,000+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ) wp-tcapsule-bridge/wp-modified-functions.php:523
  6. rtMedia for WordPress, BuddyPress and bbPress icon rtMedia for WordPress, BuddyPress and bbPress7,000+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $final_file_name ) app/main/controllers/template/rtmedia-actions.php:457
  7. non-latin attachments icon non-latin attachments60+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ) non-latin.php:218
  8. Desk-Net icon Desk-Net10+ installs apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ) desk-net.php:758

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.