How to Standardize WordPress Images File Names

opened folder for documents on table

Here is how to standardize your media file name, for keeping your WordPress uploads folder nice and clean.

A messy upload folder with inconsistent file name structure really makes me uncomfortable. I might be special in this sense, but I guess I’m not the only one.

So here is how to standardize WordPress images file names:

  1. If you already have uploaded media files, install Media File Renamer Pro

    – Only the pro version enables the Anonymize with MD5 method
    – It is a pretty cheap plugin
    – You only need to use it once, so no need for yearly license renewals (see below)
    – You only need it if you already have uploaded media files

  2. In the plugin settings, choose the Anonymize with MD5 method

  3. Backup your site

    – It’s always a good idea before bulk actions.
    WARNING: This might break the display of some images on your site. Use the great Broken Link Checker plugin to check for broken images.

  4. In the Renamer section of the Media, menu choose All and then click Rename All

  5. That covers existing media files

    The plugin doesn’t seem to rename newly uploaded files. Luckily there is a short code-snippet that does it. It also makes the plugin redundant after the bulk renaming of existing files.

  6. To automatically rename new files on upload, add the following code-snippet to function.php

    It renames the file with a random MD5 number:

<?php add_filter('wp_handle_upload_prefilter', 'custom_upload_filter'); function custom_upload_filter($file) { $path_parts = pathinfo($file['name']); $extension = $path_parts['extension']; $file['name'] = md5(microtime()) . '.' . $extension; return $file; }
Code language: HTML, XML (xml)


If you are like me and you prefer a neatly-looking uploads folder, the combination of a nice and cheap plugin and a simple code snippet can get you there quickly and easily.

Was the post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: