Many years ago in 2016, someone asked.
I would like to disable all attachment pages completely. I Googled it, but there’s just information on how to redirect to parent post or homepage. That’s not what I would call an elegant solution. Why introduce unnecessary permalinks that redirect to the homepage? Couldn’t it be disabled completely?
It just seems pointless to me that every file I upload gets its own page with a permalink. Most people just want to upload files to link to them, not creating a separate page to display them.
Redirects are bad and technically it’s not the proper use case for them – instead of redirecting existing URL you better don’t have that URL in the first place if you don’t use it. Also, on every request WP scans all rewrite rules array until finds the first match, it evaluates them using regular expressions, which is slow. Smaller array or rules means better performance. For this reason, I often remove dates, author archives, embeds, feeds etc – basically all features that aren’t used on the project.
If you want to disable media pages completely, you should use a 404 response code instead of redirection.
Instead of displaying a 404 HTTP error, some people recommend you to redirect attachment pages to the parent page instead. I think this can be a good short-term solution if the attachment pages have been indexed by Google and you want to preserve SEO ranking for these URLs. There’s a plenty of plugins on the plugin directory that let you to do that. In my opinion returning the 404 error is the correct long-term solution and if you are launching a new site, it’s best to simply disable these pages so they won’t ever end up in Google index.
The name mangling create an unique id of UUIDv4, without dashes. UUID (Universally Unique Identifier) is a 128-bit identifier that is used to uniquely identify information in computer systems. Version 4 UUIDs, also known as random UUIDs, use random numbers for its generation.
After you have mangled the slug to unique id, the changes will stay even after deactivating the plugin. This is very good. You will most likely want to activate it to keep using it for any new uploaded images to have slugs with unique id.