get_template_directory()
Gets the system path to the parent theme (not the child). Without a slash at the end.
To get the path to the child theme, use get_stylesheet_directory().
-
Use get_theme_root() to get the path to the directory with all themes.
-
Use get_theme_root_uri() to get the URL of the directory with all themes: http://example.com/wp-content/themes
-
Use get_template_directory_uri() to get the URL of the current theme, not the path.
- Use get_template() to get the name of the current theme's folder.
Instead of this function, the constant TEMPLATEPATH could be used earlier, however, the constant is considered deprecated since WP 6.4.
Uses: get_template(), get_theme_root()
Used By: get_parent_theme_file_path()
1 time — 0.000028 sec (very fast) | 50000 times — 0.17 sec (very fast) | PHP 7.1.1, WP 4.7.2
Hooks from the function
Returns
String. Path to the template.
Usage
$tpl_dir = get_template_directory();
Examples
#1 Get the path to the folder of the current theme
echo get_template_directory(); //> /home/example.com/public_html/wp-content/themes/theme_name
#2 The path to theme via the TEMPLATEPATH constant
echo TEMPLATEPATH; //> /home/example.com/public_html/wp-content/themes/theme_name
TEMPLATEPATH is considered deprecated since WP version 6.4.
Changelog
| Since 1.5.0 | Introduced. |
| Since 6.4.0 | Memoizes filter execution so that it only runs once for the current theme. |
| Since 6.4.1 | Memoization removed. |
get_template_directory() get template directory code WP 6.8.3
function get_template_directory() {
$template = get_template();
$theme_root = get_theme_root( $template );
$template_dir = "$theme_root/$template";
/**
* Filters the active theme directory path.
*
* @since 1.5.0
*
* @param string $template_dir The path of the active theme directory.
* @param string $template Directory name of the active theme.
* @param string $theme_root Absolute path to the themes directory.
*/
return apply_filters( 'template_directory', $template_dir, $template, $theme_root );
}