How would you detect if WordPress is installed in a subdirectory (not root)?

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

Common methods to achieve this are listed here:

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?

Solutions Collecting From Web of "How would you detect if WordPress is installed in a subdirectory (not root)?"

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: (URL) and (siteurl).

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', '');
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