Come verificare se un tema è attivo?
8 apr 2013, 02:50:05
Visualizzazioni: 16.4K
Voti: 16
Vorrei poter verificare se il tema TwentyTwelve è attivo. So che se dovessi verificare un plugin attivo farei qualcosa del genere:
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
if ( in_array( 'plugin-folder/plugin-folder.php', $active_plugins ) ) {
// esegui azioni
} else {
add_action( 'admin_notices', 'create-a-notice' );
}
Qual è il modo corretto per verificare se un tema è attivo in modo da poter eseguire una funzione specifica per quel tema?

Jeremiah Prummer
822
Commenti
Tutte le risposte alla domanda
2
0
Puoi utilizzare wp_get_theme
:
<?php
$theme = wp_get_theme(); // ottiene il tema corrente
if ( 'Twenty Twelve' == $theme->name || 'Twenty Twelve' == $theme->parent_theme ) {
// se sei qui, Twenty Twelve è il tema attivo oppure
// è il tema genitore del tema corrente
}
Oppure, puoi semplicemente verificare se esiste una funzione in twentytwelve -- sebbene questo metodo sia generalmente meno affidabile; un plugin, o persino un altro tema, potrebbe dichiarare twentytwelve_setup
, ad esempio.
<?php
if ( function_exists( 'twentytwelve_setup' ) ) {
// Twenty Twelve è il tema corrente o il tema genitore del tema attivo.
}

chrisguitarguy
21.5K
8 apr 2013 05:45:51
Domande correlate
6
risposte
3
risposte