Using WordPress ‘get_template()’ PHP function

The get_template() WordPress PHP function retrieves the name of the active theme.

Usage

To display the name of the active theme, use the following code:

echo esc_html(get_template());

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: get_template

Please note that get_template() will return the parent theme’s name, not the child theme’s name, if a child theme is currently activated. If you want to obtain the current theme regardless of whether it is a child theme or parent theme, use get_stylesheet.

Examples

Add the following code to your footer.php file to display the name of the active theme:

// Display the active theme name
echo 'Theme: ' . esc_html(get_template());

Create a conditional statement based on the active theme

Create a conditional statement to perform a specific action if the active theme is ‘heli’:

// Check if the active theme is 'heli'
if (get_template() === 'heli') {
    // Perform a specific action
}

Add a CSS class based on the active theme name

Add a CSS class to the body tag using the active theme name:

// Add a CSS class based on the active theme name
<body <?php body_class(get_template()); ?>>

Display a message when a specific theme is active

Display a custom message when the active theme is ‘heli’:

// Display a message when 'heli' theme is active
if (get_template() === 'heli') {
    echo 'You are using the Heli theme.';
}

Load a specific template part based on the active theme

Load a template part file based on the active theme name:

// Load a template part file based on the active theme name
get_template_part('content', get_template());