One of the things I was very keen on doing whilst building a Wordpress site which I had to run on a platform which could be considered non-standard in the Wordpress world. See my earlier blog post for details was to move themes outside of the wp-content folder, this was so that I could point wp-content to a network file system which was shared across multiple servers whilst maintaining the ability to have version control over my themes.
I spent a long time playing with the register_theme_directory function trying to get it to work with a custom theme folder with very little success until I dug into the Wordpress codebase and tracked it down to a function called get_theme_root_uri which can be found in theme.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
This seemed to be forcing themes to be in one of 3 locations, wither the WP_CONTENT_DIR (which I didn’t want as this was for storing content), ABSPATH (which I didn’t want because it was inside my git submodule) and WP_PLUGIN_DIR which was perfect for what I was looking for since I could then move WP_PLUGIN_DIR outside of WP_CONTENT_DIR
So what I did was create a new themes folder inside my plugins folder and copy the themes I wanted to use to that new location, I then needed to write a small plugin to tell Wordpress about my new theme location
1 2 3 4 5 6 7 8 9 10 11 12
I copied this into a new mu-plugins folder that I had setup so that the plugin was automatically enabled and couldn’t be disabled by the users, this meant that when I setup a new site it already knew about the new theme location and my custom themes would be available automatically.
I did come across one final gotcha which had me stumped for a while and this was because I wanted to also define WP_CONTENT_DIR to an alternative location, in doing this the new location of WP_CONTENT_DIR didn’t have a themes folder since I’d put them inside the WP_PLUGIN_DIR and this caused Wordpress to throw the wonderful
error message when trying to enable my custom themes which annoyed the hell out of me. Just creating an empty themes folder inside my redefined WP_CONTENT_DIR fixed it and all seemed to work perfectly after that.
So far I’ve learn’t that Wordpress can be incredibly frustrating when you try and make it do things that aren’t common, I feel so far I’ve beaten it into submission but no-doubt there will be other gotcha’s that I come across along the way.