I want my files being renamed automatically on upload to a random number that does not interfere with other random named files. I am new to PHP and do not want to change a code snippet every year to keep it compatible with current WordPress versions, if possible. Snippets are ok, I have WPCodebox, but they should work for a long time secure without changing. I only found posts that are at least 10 years old (e.g., https://stackoverflow.com/questions/11586284/rename-files-on-upload-in-wordpress-3-4-1) and I can not judge whether the code is still useful or safe as it is.

Does anyone know such a code snippet or a plugin for that job?

Context: I want to create a private area that is password protected. Since the media files can not be protected if accessed by their filenames (just with high-priced plugins) I want to make it very hard to be indexed by any crawlers. I hope that idea solves this problem, please tell me if I am wrong.

  • 1
    This is possibly a little misguided - indexers don't just guess at filenames - having a hard to guess attachment name won't really achieve anything. So long as your images are in password protected content and you don't have something like Yoast (other SEO plugins are available) providing a ready-made attachment index like /attachment-sitemap.xml then if the crawler / indexer can't see the attachment - it can't be indexed. You can only index the content you're given
    – Bysander
    Oct 13, 2022 at 14:05
  • @Bysander Thanks for your help and the additional information! I know how regular indexers behave, but I thought there are some malicious crawlers that do or did exactly that (e.g., for guessing “share” links of cloud providers such as Dropbox etc.). Another example with URL shorteners, OneDrive and more: wired.co.uk/article/short-url-hack-access-files. Sure, that's brute force and only 6-7 digit links. I just want to be sure that when I publish some project details that should not be available for the public or other companies, that will be the case in 99,99..% of the time. Oct 17, 2022 at 10:51

1 Answer 1


As a free workaround for sites with not that many images, I found that plugin:https://www.eurosoftlab.com/en/phoenix-media-rename/. Random Strings can be generated with Password Generators online or offline and appended to the current file name.

It is not as convenient as the automatic solution, but I hope it helps somebody.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.