¿Cómo verificar si un tema está activo?
8 abr 2013, 02:50:05
Vistas: 16.4K
Votos: 16
Me gustaría poder verificar si el tema twentytwelve está activo. Sé que si estuviera comprobando un plugin activo haría algo como:
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
if ( in_array( 'plugin-folder/plugin-folder.php', $active_plugins ) ) {
//hacer algo
} else {
add_action( 'admin_notices', 'crear-un-aviso' );
}
¿Cuál es la forma correcta de verificar si un tema está activo para poder ejecutar una función específica para ese tema?

Jeremiah Prummer
822
Comentarios
Todas las respuestas a la pregunta
2
0
Puedes usar wp_get_theme
:
<?php
$theme = wp_get_theme(); // obtiene el tema actual
if ( 'Twenty Twelve' == $theme->name || 'Twenty Twelve' == $theme->parent_theme ) {
// si estás aquí, Twenty Twelve es el tema activo o es
// el tema padre del tema actual
}
O bien, puedes simplemente verificar si existe una función en twentytwelve -- aunque esto es menos confiable; un plugin, o incluso otro tema, podría declarar twentytwelve_setup
, por ejemplo.
<?php
if ( function_exists( 'twentytwelve_setup' ) ) {
// Twenty Twelve es el tema actual o el tema padre del tema activo.
}

chrisguitarguy
21.5K
8 abr 2013 05:45:51
Preguntas relacionadas
6
respuestas
2
respuestas
3
respuestas