wp_get_theme( string $stylesheet = '', string $theme_root = '' )
Génère un objet WP_Theme pour un thème.
Paramètres
$stylesheet
(string) (Optionnel) Nom du dossier du thème choisi.
Valeur par défaut : ''
$theme_root
(string) (Optionnel) Chemin absolu de la racine du thème à chercher.
Valeur par défaut : ''
Retourne
(WP_Theme) Retourne l'objet WP_Theme. Si vous avez besoin de confirmer l'existence du thème, vérifier que l'objet existe avec la méthode WP_Theme->exists().
Structure de la fonction wp_get_theme()
Définie dans le fichier wp-includes/theme.php à la ligne 115 :
function wp_get_theme( $stylesheet = '', $theme_root = '' ) {
global $wp_theme_directories;
if ( empty( $stylesheet ) ) {
$stylesheet = get_stylesheet();
}
if ( empty( $theme_root ) ) {
$theme_root = get_raw_theme_root( $stylesheet );
if ( false === $theme_root ) {
$theme_root = WP_CONTENT_DIR . '/themes';
} elseif ( ! in_array( $theme_root, (array) $wp_theme_directories, true ) ) {
$theme_root = WP_CONTENT_DIR . $theme_root;
}
}
return new WP_Theme( $stylesheet, $theme_root );
}
Fonctions utilisées par wp_get_theme()
get_stylesheet()
Récupère le nom de la feuille de style actuelle.
get_raw_theme_root()
Génère la racine originale du thème relative au dossier wp-content.
Où trouver la fonction wp_get_theme()
dans le CMS Wordpress
Exemples
Sources
Codex Wordpress : wp_get_theme()
Autres fonctions dans le même fichier : wp-includes/theme.php