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
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).