Skip to content

Instantly share code, notes, and snippets.

@addisonhall
Created July 11, 2025 14:33
Show Gist options
  • Select an option

  • Save addisonhall/717de864b3e3f1718ebbfd58de94871a to your computer and use it in GitHub Desktop.

Select an option

Save addisonhall/717de864b3e3f1718ebbfd58de94871a to your computer and use it in GitHub Desktop.
Handy utilities to check for WordPress theme stuff
<?php
/**
* Class to check for theme stuff
*/
class Utils_Themes {
/**
* Check if specified theme is currently active
*
* @param string $theme_name Theme name as specified in theme style.css
* @return bool True if theme is currently active, false otherwise.
*/
public static function is_active( $theme_name ) {
$current_theme = wp_get_theme();
$is_theme_active = false;
if ( $current_theme === $theme_name ) {
$is_theme_active = true;
}
return $is_theme_active;
}
/**
* Check if specified theme is currently active parent theme
*
* @param string $theme_name Theme name as specified in theme style.css
* @return bool True if theme is currently active parent theme, false otherwise.
*/
public static function is_parent( $theme_name ) {
$current_theme = wp_get_theme();
$is_theme_active = false;
if ( $current_theme->parent()->get( 'Name' ) === $theme_name ) {
$is_theme_active = true;
}
return $is_theme_active;
}
/**
* Check if specified theme is currently active or parent theme
*
* @param string $theme_name Theme name as specified in theme style.css
* @return bool True if theme is currently active or parent, false otherwise.
*/
public static function is_active_or_parent( $theme_name ) {
$current_theme = wp_get_theme();
$is_theme_active = false;
if ( $current_theme === $theme_name || $current_theme->parent()->get( 'Name' ) === $theme_name ) {
$is_theme_active = true;
}
return $is_theme_active;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment