WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to be able to check if the twentytwelve theme is active. I know if I was checking for an active plugin I'd do something like:

$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
if ( in_array( 'plugin-folder/plugin-folder.php', $active_plugins ) ) {
    //do stuff
} else {
add_action( 'admin_notices', 'create-a-notice' );

What's the proper way to check if a theme is active so I can run a function for that theme?

share|improve this question
You mean something like this codex.wordpress.org/Function_Reference/wp_get_theme – Bainternet Apr 8 '13 at 0:16
That's it, thanks! I completely missed it before, but that's exactly what I was looking for. – Jeremiah Prummer Apr 8 '13 at 0:25
up vote 6 down vote accepted

You can use wp_get_theme:

$theme = wp_get_theme(); // gets the current theme
if ('twentytwelve' == $theme->name || 'twentytwelve' == $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.

if (function_exists('twentytwelve_setup')) {
   // twenty twelve is the current theme or the active theme's parent.
share|improve this answer
Works great, although I found out that the name for the twenty twelve theme is actually Twenty Twelve, which caused me some confusion for a moment. Thanks for the great answer and explanation. – Jeremiah Prummer Apr 8 '13 at 3:31
  if( 'twentytwelve' == get_option( 'template' ) ) {
    // do something
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.