Created
July 11, 2025 14:33
-
-
Save addisonhall/717de864b3e3f1718ebbfd58de94871a to your computer and use it in GitHub Desktop.
Handy utilities to check for WordPress theme stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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