clubmate.fi

A good[ish] website

Web development blog, loads of UI and JavaScript topics

Remove weird characters like ö and ä from file names in WordPress. Aka, sanitize file upload image names.

Filed under: WordPress/PHP— Tagged with: snippets

Sometimes when you move your site to another server and the database has different charset (or something else mysterious happens), you may find some of your images broken cause of the weird characters in the names. To be on the safe side, it's nice to sanitize the file names.

There is a simple function to do it. Just paste this into your themes functions.php file.

add_filter('sanitize_file_name', 'sa_sanitize_chars', 10);
  function sa_sanitize_chars ($filename) {

  return remove_accents( $filename );
}

Source

Comments would go here, but the commenting system isn’t ready yet, sorry.

  • © 2022 Antti Hiljá
  • About
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!