WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

WPMU VHOST Constant

Description

When installing WordPress MU (WPMU), an administrator can choose to use sub-domains or sub-directories for blog addresses. This presents a challenge for WordPress Plugin and Theme developers. How can a Plugin of Theme function determine if WordPress MU is using sub-domains or sub-directories?

The VHOST constant stores whether WordPress MU is using sub-domains for blog addresses. If an administrator chooses to use sub-domains, VHOST contains a value of "yes". If the administrator chooses to use sub-directories, VHOST is set with a value of "no".

Usage

A WordPress Plugin or Theme function can access the value of VHOST using the PHP constant function.
<?php constant"VHOST" ); ?>

Example

The VHOST constant could be used within a plugin to control a logical test. The code below will print a different message depending on whether WPMU is using sub-domains or sub-directories.

    if( constant( "VHOST" ) == 'yes' )
        echo "I'm using sub-domains for blog addresses!";
    else
        echo "I'm using sub-folders for blog addresses.";

References

For more information on the PHP Constant VHOST used in WordPress MU, see: