Title: Automatic Renaming?
Last modified: August 31, 2016

---

# Automatic Renaming?

 *  [t4gal](https://wordpress.org/support/users/t4gal/)
 * (@t4gal)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/)
 * Hello,
 * I just installed this plugin and I’m very confused about how it works.
 * The reason I installed it is because I have a lot of images with accented characters,
   which are not displaying properly, so I need to clean up the accented characters,
   which is what I understood this plugin does.
 * All I’ve done so far is install and activate the plugin. I then went to the media
   library and saw the renaming column, and all of the images with accented characters
   are already listed as “automatically renamed”. Unfortunately, they haven’t actually
   been renamed. The file name still has the same accented characters, nothing has
   changed. And because they’re listed as already renamed, I don’t have the option
   to click a button to rename them.
 * I may be missing something, because it seems strange to me that the plugin would
   even try to automatically rename files without me even touching any settings 
   or buttons? For all I know it may have renamed files that I didn’t want changed.
   This leads me to think that there is something I need to click or approve in 
   order to rename the files? I’ve looked but I don’t see any such option.
 * Any clarification would be great, thank you!
 * [https://wordpress.org/plugins/media-file-renamer/](https://wordpress.org/plugins/media-file-renamer/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Jordy Meow](https://wordpress.org/support/users/tigroumeow/)
 * (@tigroumeow)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941471)
 * Hello 🙂
 * > The reason I installed it is because I have a lot of images with accented characters,
   > which are not displaying properly, so I need to clean up the accented characters,
   > which is what I understood this plugin does.
 * Not really. It just renames the filenames depending on the media titles (or the
   post they are attached to).
 * > And because they’re listed as already renamed, I don’t have the option to click
   > a button to rename them.
 * Yes, because the filename already matches perfectly the media title I guess. 
   This is why they don’t need to be renamed.
 * > For all I know it may have renamed files that I didn’t want changed.
 * I don’t believe so. It would only rename if you change the media title.
 * > Any clarification would be great, thank you!
 * The way the plugin renames can be modified through a filter. Do you know how 
   to program using WordPress a bit? Have a look at this: [https://wordpress.org/plugins/media-file-renamer/faq/](https://wordpress.org/plugins/media-file-renamer/faq/).
 * If you use this plugin’s filter, you can basically use this little piece of code(
   and add it anywhere in your website, probably in the functions.php of your theme
   for example) and work on this $new variable. In your case, it seems like this
   $new still has the accents. You need to write some code to replace the accents
   by the characters with no accents and return this $new. Then the plugin will 
   automatically react on this and it will have actually the behavior you need. 
   It’s easy to find code snippet to remove the accents in PHP, like here: [http://stackoverflow.com/questions/3371697/replacing-accented-characters-php](http://stackoverflow.com/questions/3371697/replacing-accented-characters-php).
 *  Thread Starter [t4gal](https://wordpress.org/support/users/t4gal/)
 * (@t4gal)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941632)
 * I appreciate your answer, that clears things up!
 * I checked out the links you posted and have tried messing around with the bit
   of code from your FAQ and the following bit of code from the other link you posted:
 *     ```
       function replaceAccent($string, $replacement = '_')
       {
           $alnumPattern = '/^[a-zA-Z0-9 ]+$/';
   
           if (preg_match($alnumPattern, $string)) {
               return $string;
           }
   
           $ret = array_map(
               function ($chr) use ($alnumPattern, $replacement) {
                   if (preg_match($alnumPattern, $chr)) {
                       return $chr;
                   } else {
                       $chr = @iconv('ISO-8859-1', 'ASCII//TRANSLIT', $chr);
                       if (strlen($chr) == 1) {
                           return $chr;
                       } elseif (strlen($chr) > 1) {
                           $ret = '';
                           foreach (str_split($chr) as $char2) {
                               if (preg_match($alnumPattern, $char2)) {
                                   $ret .= $char2;
                               }
                           }
                           return $ret;
                       } else {
                           // replace whatever iconv fail to convert by something else
                           return $replacement;
                       }
                   }
               },
               str_split($string)
           );
   
           return implode($ret);
       }
       ```
   
 * But I can’t seem to figure out how to make it work. I’m not very experienced 
   in this kind of stuff, so I was just taking some stabs in the dark. I would appreciate
   any direction you might be able to give as to how to implement these two, or 
   even if the bit of code I posted here is the right thing to use.
 * Thanks again for your help!
 *  Plugin Author [Jordy Meow](https://wordpress.org/support/users/tigroumeow/)
 * (@tigroumeow)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941665)
 * You mean you don’t know how to put and glue all that?
 * You could try to put the function replaceAccent() in your functions.php.
 * Then try to add this after it:
 *     ```
       add_filter( 'mfrh_new_filename', 'my_anti_accent_filter', 10, 3 );
   
       function my_anti_accent_filter( $new, $old, $post ) {
         return replaceAccent( $new );
       }
       ```
   
 * Then look at the list of your media. The plugin should propose you to rename 
   them to non-accentuated filenames (if the above function works of course :p).
 *  Thread Starter [t4gal](https://wordpress.org/support/users/t4gal/)
 * (@t4gal)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941673)
 * Thanks again for your answer.
 * I tried exactly what you said, but unfortunately nothing changed. I still don’t
   have the option to rename the accented characters. I thought maybe it was just
   the replaceAccent() function that wasn’t working, so I did a quick search and
   tried about 10 other bits of code that claimed to do the same thing, but none
   of them worked. I’m not sure if I’m missing something, doing something wrong,
   or if none of these bits of code that I’ve found actually work, as this is fairly
   foreign to me, so I’m not sure where to go from here.
 * This is exactly what I used, in my themes functions.php file:
 *     ```
       function replaceAccent($string, $replacement = '_')
       {
           $alnumPattern = '/^[a-zA-Z0-9 ]+$/';
   
           if (preg_match($alnumPattern, $string)) {
               return $string;
           }
   
           $ret = array_map(
               function ($chr) use ($alnumPattern, $replacement) {
                   if (preg_match($alnumPattern, $chr)) {
                       return $chr;
                   } else {
                       $chr = @iconv('UTF8', 'ASCII//TRANSLIT', $chr);
                       if (strlen($chr) == 1) {
                           return $chr;
                       } elseif (strlen($chr) > 1) {
                           $ret = '';
                           foreach (str_split($chr) as $char2) {
                               if (preg_match($alnumPattern, $char2)) {
                                   $ret .= $char2;
                               }
                           }
                           return $ret;
                       } else {
                           // replace whatever iconv fail to convert by something else
                           return $replacement;
                       }
                   }
               },
               str_split($string)
           );
   
           return implode($ret);
       }
   
       add_filter( 'mfrh_new_filename', 'my_anti_accent_filter', 10, 3 );
   
       function my_anti_accent_filter( $new, $old, $post ) {
         return replaceAccent( $new );
       }
       ```
   
 * If I bought the pro version, would I be able to manually go through each image
   with accented characters and replace them by hand? Would they then be updated
   in the database and all references in posts and pages?
 * Thanks again for your help.
 *  Thread Starter [t4gal](https://wordpress.org/support/users/t4gal/)
 * (@t4gal)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941791)
 * I can’t seem to get this working, so it looks like I may just need to go the 
   manual route.
 * Before I buy the pro version to fix my problem, can you confirm the functionality
   of it? Will I be able to manually rename any image, including ones that have 
   already been “automatically renamed”? I want to make sure I correctly understand
   how the pro plugin works before I spend the money on it.
 * Thanks!
 *  Plugin Author [Jordy Meow](https://wordpress.org/support/users/tigroumeow/)
 * (@tigroumeow)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941795)
 * Actually I tried the code above and I couldn’t properly test it because in all
   my cases, the plugin/WordPress removes those accents from the filenames. I have
   no idea why your install requires you to attempt to do it manually…
 * Could you contact me at [support@meow.fr](https://wordpress.org/support/topic/automatic-renaming/support@meow.fr?output_format=md)?
   Maybe I can check more about this issue…
 * About this:
 * > Before I buy the pro version to fix my problem, can you confirm the functionality
   > of it? Will I be able to manually rename any image, including ones that have
   > already been “automatically renamed”?
 * Yes 🙂 You can override and manually rename anything you like.
 *  Thread Starter [t4gal](https://wordpress.org/support/users/t4gal/)
 * (@t4gal)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941808)
 * Thanks for your response, I’ve sent you an email to the address provided.
 *  Thread Starter [t4gal](https://wordpress.org/support/users/t4gal/)
 * (@t4gal)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941848)
 * Hi there,
 * I sent an email about a week ago, and then sent another a few days after, but
   have received no response. Did you get my emails?
 * I think for now I’ll just buy the pro version and start manually renaming, but
   like I said, I have lots of files to do so it would be nice if I could get the
   automatic renaming to work, just to save me time.
 * Thanks for your time.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Automatic Renaming?’ is closed to new replies.

 * ![](https://ps.w.org/media-file-renamer/assets/icon-256x256.png?rev=2791577)
 * [Media File Renamer: Rename for better SEO (AI-Powered)](https://wordpress.org/plugins/media-file-renamer/)
 * [Support Threads](https://wordpress.org/support/plugin/media-file-renamer/)
 * [Active Topics](https://wordpress.org/support/plugin/media-file-renamer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-file-renamer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-file-renamer/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [t4gal](https://wordpress.org/support/users/t4gal/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/automatic-renaming/#post-6941848)
 * Status: not resolved