WP_Theme::exists() WordPress Method

The WP_Theme::exists() method is used to check whether a given theme exists. This is useful when you need to programmatically load a theme or template. For example, if you want to load a theme file only if it exists, you can use this method: if ( WP_Theme::exists( 'my-theme' ) ) { // load the theme }

WP_Theme::exists() #

Determines whether the theme exists.


Description

A theme with errors exists. A theme with the error of ‘theme_not_found’, meaning that the theme’s directory was not found, does not exist.


Top ↑

Return

(bool) Whether the theme exists.


Top ↑

Source

File: wp-includes/class-wp-theme.php

	public function exists() {
		return ! ( $this->errors() && in_array( 'theme_not_found', $this->errors()->get_error_codes(), true ) );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.