get_template()
Gets the directory name of the parent theme (or the current one if a child theme is not used).
The function is useful when you are working with child themes and want to get the name of the parent theme.
This is a wrapper for get_option( 'template' ), applying the filter template to the result.
Use get_stylesheet() to get the name of the current theme - child or parent.
Use get_theme_root() to get the system path to the parent theme.
Hooks from the function
Returns
String. The directory name of the current theme.
Usage
$template = get_template();
Examples
#1 Get the name of the current Theme
For example, if your current active theme is named wp-kama, then:
$template = get_template(); echo esc_html( $template ); // output: wp-kama
Note that the function will return the name of the parent theme, not the child theme, even if the child theme is activated.
Use get_stylesheet() to get the current theme, regardless of whether it is a child or parent theme.
Changelog
| Since 1.5.0 | Introduced. |
get_template() get template code WP 6.9.1
function get_template() {
/**
* Filters the name of the active theme.
*
* @since 1.5.0
*
* @param string $template active theme's directory name.
*/
return apply_filters( 'template', get_option( 'template' ) );
}