register_theme_directory

The timeline below displays how wordpress function register_theme_directory has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Registers a directory that contains themes.
 *
 * @since 2.9.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $directory Either the full filesystem path to a theme folder
 *                          or a folder within WP_CONTENT_DIR.
 * @return bool True if successfully registered a directory that contains themes,
 *              false if the directory does not exist.
 */
function register_theme_directory($directory)
{
    global $wp_theme_directories;
    if (!file_exists($directory)) {
        // Try prepending as the theme directory could be relative to the content directory.
        $directory = WP_CONTENT_DIR . '/' . $directory;
        // If this directory does not exist, return and do not register.
        if (!file_exists($directory)) {
            return false;
        }
    }
    if (!is_array($wp_theme_directories)) {
        $wp_theme_directories = array();
    }
    $untrailed = untrailingslashit($directory);
    if (!empty($untrailed) && !in_array($untrailed, $wp_theme_directories, true)) {
        $wp_theme_directories[] = $untrailed;
    }
    return true;
}

WordPress Version: 5.4

/**
 * Register a directory that contains themes.
 *
 * @since 2.9.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR
 * @return bool
 */
function register_theme_directory($directory)
{
    global $wp_theme_directories;
    if (!file_exists($directory)) {
        // Try prepending as the theme directory could be relative to the content directory.
        $directory = WP_CONTENT_DIR . '/' . $directory;
        // If this directory does not exist, return and do not register.
        if (!file_exists($directory)) {
            return false;
        }
    }
    if (!is_array($wp_theme_directories)) {
        $wp_theme_directories = array();
    }
    $untrailed = untrailingslashit($directory);
    if (!empty($untrailed) && !in_array($untrailed, $wp_theme_directories)) {
        $wp_theme_directories[] = $untrailed;
    }
    return true;
}

WordPress Version: 4.3

/**
 * Register a directory that contains themes.
 *
 * @since 2.9.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR
 * @return bool
 */
function register_theme_directory($directory)
{
    global $wp_theme_directories;
    if (!file_exists($directory)) {
        // Try prepending as the theme directory could be relative to the content directory
        $directory = WP_CONTENT_DIR . '/' . $directory;
        // If this directory does not exist, return and do not register
        if (!file_exists($directory)) {
            return false;
        }
    }
    if (!is_array($wp_theme_directories)) {
        $wp_theme_directories = array();
    }
    $untrailed = untrailingslashit($directory);
    if (!empty($untrailed) && !in_array($untrailed, $wp_theme_directories)) {
        $wp_theme_directories[] = $untrailed;
    }
    return true;
}

WordPress Version: 4.0

/**
 * Register a directory that contains themes.
 *
 * @since 2.9.0
 *
 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR
 * @return bool
 */
function register_theme_directory($directory)
{
    global $wp_theme_directories;
    if (!file_exists($directory)) {
        // Try prepending as the theme directory could be relative to the content directory
        $directory = WP_CONTENT_DIR . '/' . $directory;
        // If this directory does not exist, return and do not register
        if (!file_exists($directory)) {
            return false;
        }
    }
    if (!is_array($wp_theme_directories)) {
        $wp_theme_directories = array();
    }
    $untrailed = untrailingslashit($directory);
    if (!empty($untrailed) && !in_array($untrailed, $wp_theme_directories)) {
        $wp_theme_directories[] = $untrailed;
    }
    return true;
}

WordPress Version: 3.7

/**
 * Register a directory that contains themes.
 *
 * @since 2.9.0
 *
 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR
 * @return bool
 */
function register_theme_directory($directory)
{
    global $wp_theme_directories;
    if (!file_exists($directory)) {
        // Try prepending as the theme directory could be relative to the content directory
        $directory = WP_CONTENT_DIR . '/' . $directory;
        // If this directory does not exist, return and do not register
        if (!file_exists($directory)) {
            return false;
        }
    }
    $wp_theme_directories[] = $directory;
    return true;
}