Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 3 down vote accepted

You can use wp_get_theme:

<?php
$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.

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

 
discard

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.