How to check if a theme is active?

You can use wp_get_theme:

<?php
$theme = wp_get_theme(); // gets the current theme
if ( 'Twenty Twelve' == $theme->name || 'Twenty Twelve' == $theme->parent_theme ) {
    // if you're here Twenty Twelve is the active theme or is
    // the current theme's parent theme
}

Or, you can simply check if a function in twentytwelve exists — which is likely less reliable; a plugin, or even another theme, could declare twentytwelve_setup, for instance.

<?php
if ( function_exists( 'twentytwelve_setup' ) ) {
   // Twenty Twelve is the current theme or the active theme's parent.
}

Leave a Comment