I want to check if a WordPress installation is working from a subdirectory.

Common methods to achieve this are listed here: https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

these usually involve changing an index file and requiring WordPress main file from there, perhaps changing rules in htaccess if using Apache - there's no setting up constants from what I can see

so, how would you detect reliably if WordPress is not running from a directory root?


2 Answers 2


You need to check if the siteurl differs from the home URL:

if ( get_option( 'siteurl' ) !== get_option( 'home' ) ) { // whatever

This also works if home is a subdirectory of the root, with WordPress installed in yet another subdirectory. For example: domain.com/blog (URL) and domain.com/blog/wordpress (siteurl).

  • thanks I also thought of that and should have mentioned in OP question -- however, do you think it's reliable in 100% of the cases?
    – unfulvio
    Feb 3, 2016 at 8:41
  • Yes, because that is the definition of where WordPress is installed. If it differs from the URL, it's a subdirectory install.
    – fischi
    Feb 3, 2016 at 9:56
  • what if it's not a subdirectory install but the URLS are still different? For example sites which have different domains pointing to the same install
    – paul
    Feb 4, 2016 at 10:17
  • @paul even then both options are the same, and the handling of multiple domains is done somewhere else. Do you have an example where this is not the case?
    – fischi
    Feb 4, 2016 at 10:18
  • for example: my.bluehost.com/cgi/help/wordpress_url#to_url - in theory one of those settings could be the temp URL and the other could be the real domain
    – paul
    Feb 4, 2016 at 10:26

I just came across for the same question and found another way to figure it out. You can also use the defined Constants from the wp-config.php file. SUBDOMAIN_INSTALL would be the key.

Example wp-config excerpt for Multisite settings would be

define('WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'intern.cc.dev');
define('PATH_CURRENT_SITE', '/');

In your code

// only run condition, when we are in MS
if( is_multisite() ):

   // check for subfolder installation flag
   if( SUBDOMAIN_INSTALL === false):

      // optional, check if you are on the home WP or a sub WP
      if( get_current_blog_id() > 1):

         // do whatever you need to to here

      endif; // end blog id check
   endif; // end subfolder installation 
endif; // end multisite check

Your Answer

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

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