admin管理员组文章数量:1124679
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?
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?
Share Improve this question asked Feb 2, 2016 at 10:02 unfulviounfulvio 1,8247 gold badges32 silver badges63 bronze badges 03 Answers
Reset to default 2You 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).
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
Try this:
if ( '/' !== site_url( '', 'relative') ) {
本文标签: directoryHow would you detect if WordPress is installed in a subdirectory (not root)
版权声明:本文标题:directory - How would you detect if WordPress is installed in a subdirectory (not root)? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736644429a1946073.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论