WordPress is a popular content management system (CMS) that allows you to create and manage websites. You can use WordPress to create blogs, stores, and other online properties. WordPress also allows you to upload files and folders to your website. You can use the WordPress randomization feature to randomly select filename values for uploaded files. This feature helps you keep your uploaded files organized and makes it easier to find the file you need when you need it. To use the WordPress randomization feature, first open up your WordPress site in a new browser window or tab. Then click on the three lines in the top left corner of your screen (the blue bar). This will open up a new window with some basic information about your site. On the right side of this window, you will see a list of all of your posts and pages. Under Posts, you will see a list of all of the posts that have been created on your site. Under Pages, you will see a list of all of the pages that have been created on your site. In this example, we are going to focus on one post: “How to Randomize Uploaded Filenames in WordPress” In this post, we are going to show how to randomly select filename values for uploaded files using the WordPress randomization feature. We will also show how this feature can help keep our uploaded files organized and make it easier to find the file we need when we need it.


And to make matters worse, if you’re using Skitch to capture screenshots of various terminal commands, it captures the full path from Terminal and uses that as the file name, which is just absurdly long.

The much simpler solution is to simply add a couple of lines of code to change all uploaded images to a simple randomized file name, and then trim it down to the first 8 characters to make sure that image paths in the HTML aren’t too crazy.

Paste the code into your functions.php file, located in your theme folder, and it should immediately start working.

This works by adding a function to the sanitize_file_name filter that does the work and returns the new file name. WordPress will attempt to use that new name – but if there’s a clash, it’ll add a -1 to the end and continue with numbering until it doesn’t have a clash anymore. Realistically that’s unlikely to happen, but it’s good to know that it won’t be an issue.