Find out if Wordpress multisite uses subdirectory or subdomain for new blogs Find out if Wordpress multisite uses subdirectory or subdomain for new blogs wordpress wordpress

Find out if Wordpress multisite uses subdirectory or subdomain for new blogs


Well, we have the very constant defined in wp-config.php:

if ( defined( 'SUBDOMAIN_INSTALL' ) ) {    if( SUBDOMAIN_INSTALL )        echo '<h2>Is: SUBDOMAIN</h2>';    else        echo '<h2>Is: SUBDIRECTORY</h2>';}


You can use wp_get_sites() to get information about your blogs. It will return an array containing information about all existing blogs.

Example result from the documentation:

Array(    [0] => Array(        [blog_id] => 1        [site_id] => 1        [domain] => example.com        [path] => /        [registered] => 2013-11-08 17:56:46        [last_updated] => 2013-11-08 18:57:19        [public] => 1        [archived] => 0        [mature] => 0        [spam] => 0        [deleted] => 0        [lang_id] => 0    )    [1] => Array(        [blog_id] => 2        [site_id] => 1        [domain] => example.com        [path] => /examplesubsite/        [registered] => 2013-11-08 18:07:22        [last_updated] => 2013-11-08 18:13:40        [public] => 1        [archived] => 0        [mature] => 0        [spam] => 0        [deleted] => 0        [lang_id] => 0    ))

[0] will be your main blog, so I'd ignore this. But by checking the first blog after that you should be able to get the information.

$info = wp_get_sites();if ($info[1]['path'] == "/") {    // the installation uses subdomains}else {    // the installation uses subdirectorys}

Of course this only works when there is at least one additional blog created, but I couldn't find any other option to check for.