I have a must use plugin that uses register_theme_directory() but no matter what path I pass in, it always returns false.

For some background I am using domain based database switching in the wp-config to manage multiple distinct sites with one install, (i am not using a network install because each site needs it own unique users database). I have some themes I want to only be available to one specific site, so I put it in a special directory and try to register the theme directory in a mu-plugin if the domain is accessed.

Here is the relevant portion of my directory-structure:

 |-> site-themes
      |-> site-a
           |-> theme-1
           |-> theme-2

I have tried the following:

if ( [check site domain ] ) {
    register_theme_directory( '[wordpress root]/wp-content/site-themes/site-a' );

When that didn't work I figured it must need each theme to have its directory registered so I tried this:

if ( [check site domain ] ) {
    register_theme_directory( '[wordpress root]/wp-content/site-themes/site-a/theme-1' );
    register_theme_directory( '[wordpress root]/wp-content/site-themes/site-a/theme-2' );

But that didn't work either. I am sure I am missing something simple. Any suggestions?

  • If it returns false, then it's very likely because the directory does not exist. And you can also try using a path relative to wp-content - register_theme_directory( 'site-themes/site-a' )
    – Sally CJ
    Aug 2 '19 at 1:54
  • Have you verified that whatever you're using for [check site domain ] is working? Aug 2 '19 at 1:56
  • And try echo 'my conditional check is ok'; before your register_theme_directory() call to confirm your conditional is not actually the one that returned false.
    – Sally CJ
    Aug 2 '19 at 2:00
  • Yes I use strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) ) for the conditional check just like I do in wp-config and also I echoed the result of register_theme_directory() to see that it was executing and it was returning false. And the folder does exist so I see no reason why this doesn't work.
    – user172867
    Aug 2 '19 at 2:36
  • 2
    Nevermind, I feel stupid. After trying to check file_exists() for a sanity check I saw that the directory did in fact not exist, confusingly at first until I realized that the directory did not exist because wp-content was listed in my .gitignore so when I committed it to deploy to my server the directory was removed.
    – user172867
    Aug 2 '19 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy