¿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?

1
Comentarios

¿Te refieres a algo como esto? http://codex.wordpress.org/Function_Reference/wp_get_theme

Bainternet Bainternet
8 abr 2013 03:16:51
Todas las respuestas a la pregunta 2
0
29

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.
}
8 abr 2013 05:45:51
1
10
  if( 'twentytwelve' == get_option( 'template' ) ) {
    // hacer algo
  }
8 abr 2013 05:26:20
Comentarios

Realmente me gusta esta opción e incluso podrías dirigirte a otras funciones que se relacionen específicamente con lo que intentas hacer en el plugin. Buena respuesta @liying

Tony Djukic Tony Djukic
11 ene 2021 16:33:05