wp_theme_has_theme_json

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

WordPress Version: 6.3

/**
 * Checks whether a theme or its parent has a theme.json file.
 *
 * @since 6.2.0
 *
 * @return bool Returns true if theme or its parent has a theme.json file, false otherwise.
 */
function wp_theme_has_theme_json()
{
    static $theme_has_support = array();
    $stylesheet = get_stylesheet();
    if (isset($theme_has_support[$stylesheet]) && !wp_is_development_mode('theme')) {
        return $theme_has_support[$stylesheet];
    }
    $stylesheet_directory = get_stylesheet_directory();
    $template_directory = get_template_directory();
    // This is the same as get_theme_file_path(), which isn't available in load-styles.php context
    if ($stylesheet_directory !== $template_directory && file_exists($stylesheet_directory . '/theme.json')) {
        $path = $stylesheet_directory . '/theme.json';
    } else {
        $path = $template_directory . '/theme.json';
    }
    /** This filter is documented in wp-includes/link-template.php */
    $path = apply_filters('theme_file_path', $path, 'theme.json');
    $theme_has_support[$stylesheet] = file_exists($path);
    return $theme_has_support[$stylesheet];
}

WordPress Version: 6.2

/**
 * Checks whether a theme or its parent has a theme.json file.
 *
 * @since 6.2.0
 *
 * @return bool Returns true if theme or its parent has a theme.json file, false otherwise.
 */
function wp_theme_has_theme_json()
{
    static $theme_has_support = null;
    if (null !== $theme_has_support && !WP_DEBUG && !(defined('WP_RUN_CORE_TESTS') && WP_RUN_CORE_TESTS)) {
        return $theme_has_support;
    }
    // Does the theme have its own theme.json?
    $theme_has_support = is_readable(get_stylesheet_directory() . '/theme.json');
    // Look up the parent if the child does not have a theme.json.
    if (!$theme_has_support) {
        $theme_has_support = is_readable(get_template_directory() . '/theme.json');
    }
    return $theme_has_support;
}