The get_current_theme() WordPress PHP function retrieves the current theme’s name.
Usage
To use the get_current_theme() function, simply call it and assign its output to a variable:
$theme_name = get_current_theme(); echo esc_html($theme_name);
Parameters
- None
More information
See WordPress Developer Resources: get_current_theme
Examples
Display the current theme name in a header
This example displays the current theme name in an H2 tag.
$theme_name = get_current_theme(); echo '<h2>' . esc_html($theme_name) . '</h2>';
Use the current theme name as a body class
This example adds the current theme name as a class to the body tag.
$theme_name = get_current_theme(); echo '<body class="' . esc_attr($theme_name) . '">';
Display a message depending on the current theme
This example shows a different message for each theme.
$theme_name = get_current_theme(); if ($theme_name === 'Theme A') { echo 'Welcome to Theme A!'; } elseif ($theme_name === 'Theme B') { echo 'Welcome to Theme B!'; } else { echo 'Welcome to our website!'; }
Load a specific stylesheet based on the current theme
This example loads a stylesheet file depending on the current theme name.
$theme_name = get_current_theme(); wp_enqueue_style('custom-style', get_template_directory_uri() . "/css/{$theme_name}.css");
Add a theme-specific widget area
This example registers a new widget area only if the current theme is “Theme X”.
$theme_name = get_current_theme(); if ($theme_name === 'Theme X') { register_sidebar(array( 'name' => 'Theme X Special Widget Area', 'id' => 'theme_x_special_widget_area', 'description' => 'A special widget area for Theme X.', 'before_widget' => '<div class="widget">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', )); }