Another Impossible WP Solution

I was trying to emulate the appearance of multiple subfolders of files in the installations root directory, but these folder names would conflict with pages that need to be the same name.

In other words, I wanted media files to appear as if they were in the same folder as the page as if it the page URL was a real folder.

would be the page for a court case and would be a document referenced in it

I COULD change the upload directory to the install root and then subfolders using a plugin that allows organizing media files this way. HOWEVER, calling on the page slug will cause the server to open the file directory for the actual folder rather than the page in the WP database.

So I needed to have the media files in another directory than the install to eliminate conflicts, and then have slugs for files just start at the install directory path.

would become

And of course I needed this done for all media files, not manually adding redirects for each one.

{NOTE: This was a client requirement. Yes, it’s crazy to be so concerned with URLS, but that’s the demand.}

After talking with my friend Bill Caffery, we agreed we needed slugs for the file URLS, but didn’t know how to automate it. I was thinking some wildcard redirects in the HTACCESS files of the upload directory and/or install directory, but that would only work one way, so to speak. He was thinking to hell with WordPress and use something else like Symphony. I wasn’t down with learning another platform as my model has always been to focus and excel at core competencies, and that means limiting the software I use for given tasks. I also didn’t want the client to have to add lines of redirects and what-not.

So I was counting on finding a way to get WordPress to create slugs for the media files. After all, it already odes this easily and seamlessly for posts and pages. So I needed two things:

(1) A media library management system that allowed sub-folders;
(2) A plugin (ideally, rather than hacking the PHP) to designate the ‘uploads’ folder.

Or at least that’s what I thought I would need, and after some experimentation found what actually worked.

First, the media library system had to NOT be independent of the media library like many of the plugins did — it needed all media to register with WordPress so it would place slugs for their URLs in the database. This was accomplished by using the Media Library Folders plugin.

Secondly, I got another plugin to move the location where media was uploaded, but then the plugin above wasn’t able to manage the files outside the usual default folder.  So after many attempts and database table cleanings, I decided to leave the folders in the usual place and just change the URL to create correct slugs. It was trial and error that I realized the second plugin actually did this, WP Original Media Path.

I had to check a box saying I knew what I was doing (I lied) and it gave a second setting box. The main setting was the path for the media folders and files, which I tried to make the install root — successful but not solving the problem. I THOUGHT this was the location/pathname of the files, but it was not. It was the slug. The hidden setting was the actual folder. So I made the former the URL base I wanted and the latter the default folder.

I found I had to recreate the folders and upload the files manually, but otherwise, it worked!

Like my father always says, “The difficult you can do right away; the impossible takes a little time.”