Title: get_template_directory
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_template_directory(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#more-information)
    - [Usage](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#usage)
    - [Notes](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#notes)
 * [Source](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#wp--skip-link--target)

Retrieves template directory path for the active theme.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#return)󠁿

 string Path to active theme’s template directory.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#more-information)󠁿

### 󠀁[Usage](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#usage)󠁿

    ```php
    echo get_template_directory();
    ```

Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme),
not a URI.

In the case a child theme is being used, the absolute path to the parent theme directory
will be returned. Use [get_stylesheet_directory()](https://developer.wordpress.org/reference/functions/get_stylesheet_directory/)
to get the absolute path to the child theme directory.

To retrieve the URI of the stylesheet directory use [get_stylesheet_directory_uri()](https://developer.wordpress.org/reference/functions/get_stylesheet_directory_uri/)
instead.

### 󠀁[Notes](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#notes)󠁿

 * Uses: [get_theme_root()](https://developer.wordpress.org/reference/functions/get_theme_root/)
   to retrieve the absolute path to the themes directory, [get_template()](https://developer.wordpress.org/reference/functions/get_template/)
   to retrieve the directory name of the current theme.
 * Does not output a trailing slash

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/theme.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/theme.php#L337)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/theme.php#L337-L352)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#hooks)󠁿

 [apply_filters( ‘template_directory’, string $template_dir, string $template, string $theme_root )](https://developer.wordpress.org/reference/hooks/template_directory/)

Filters the active theme directory path.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#related)󠁿

| Uses | Description | 
| [get_theme_root()](https://developer.wordpress.org/reference/functions/get_theme_root/)`wp-includes/theme.php` |

Retrieves path to themes directory.

  | 
| [get_template()](https://developer.wordpress.org/reference/functions/get_template/)`wp-includes/theme.php` |

Retrieves name of the active theme.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#)

| Used by | Description | 
| [WP_Debug_Data::get_wp_parent_theme()](https://developer.wordpress.org/reference/classes/wp_debug_data/get_wp_parent_theme/)`wp-admin/includes/class-wp-debug-data.php` |

Gets the WordPress parent theme section of the debug data.

  | 
| [wp_set_template_globals()](https://developer.wordpress.org/reference/functions/wp_set_template_globals/)`wp-includes/template.php` |

Set up the globals used for template loading.

  | 
| [get_block_asset_url()](https://developer.wordpress.org/reference/functions/get_block_asset_url/)`wp-includes/blocks.php` |

Gets the URL to a block asset.

  | 
| [wp_theme_has_theme_json()](https://developer.wordpress.org/reference/functions/wp_theme_has_theme_json/)`wp-includes/global-styles-and-settings.php` |

Checks whether a theme or its parent has a theme.json file.

  | 
| [WP_Theme_JSON_Resolver::get_style_variations()](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_style_variations/)`wp-includes/class-wp-theme-json-resolver.php` |

Returns the style variations defined by the theme.

  | 
| [_get_block_template_file()](https://developer.wordpress.org/reference/functions/_get_block_template_file/)`wp-includes/block-template-utils.php` |

Retrieves the template file from the theme for a given slug.

  | 
| [_get_block_templates_files()](https://developer.wordpress.org/reference/functions/_get_block_templates_files/)`wp-includes/block-template-utils.php` |

Retrieves the template files from the theme.

  | 
| [WP_Theme_JSON_Resolver::get_file_path_from_theme()](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/)`wp-includes/class-wp-theme-json-resolver.php` |

Builds the path to the given file and checks that it is readable.

  | 
| [locate_block_template()](https://developer.wordpress.org/reference/functions/locate_block_template/)`wp-includes/block-template.php` |

Finds a block template with equal or higher specificity than a given PHP template file.

  | 
| [resolve_block_template()](https://developer.wordpress.org/reference/functions/resolve_block_template/)`wp-includes/block-template.php` |

Returns the correct ‘wp_template’ to render for the request template type.

  | 
| [WP_Customize_Manager::prepare_starter_content_attachments()](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/)`wp-includes/class-wp-customize-manager.php` |

Prepares starter content attachments.

  | 
| [get_parent_theme_file_path()](https://developer.wordpress.org/reference/functions/get_parent_theme_file_path/)`wp-includes/link-template.php` |

Retrieves the path of a file in the parent theme.

  | 
| [get_theme_file_path()](https://developer.wordpress.org/reference/functions/get_theme_file_path/)`wp-includes/link-template.php` |

Retrieves the path of a file in the theme.

  | 
| [get_theme_file_uri()](https://developer.wordpress.org/reference/functions/get_theme_file_uri/)`wp-includes/link-template.php` |

Retrieves the URL of a file in the theme.

  | 
| [_load_textdomain_just_in_time()](https://developer.wordpress.org/reference/functions/_load_textdomain_just_in_time/)`wp-includes/l10n.php` |

Loads plugin and theme text domains just-in-time.

  | 
| [get_editor_stylesheets()](https://developer.wordpress.org/reference/functions/get_editor_stylesheets/)`wp-includes/theme.php` |

Retrieves any registered editor stylesheet URLs.

  | 
| [validate_current_theme()](https://developer.wordpress.org/reference/functions/validate_current_theme/)`wp-includes/theme.php` |

Checks that the active theme has the required files.

  | 
| [load_theme_textdomain()](https://developer.wordpress.org/reference/functions/load_theme_textdomain/)`wp-includes/l10n.php` |

Loads the theme’s translated strings.

  | 
| [get_attachment_icon_src()](https://developer.wordpress.org/reference/functions/get_attachment_icon_src/)`wp-includes/deprecated.php` |

Retrieve icon URL and Path.

  | 
| [wp_templating_constants()](https://developer.wordpress.org/reference/functions/wp_templating_constants/)`wp-includes/default-constants.php` |

Defines templating-related WordPress constants.

  |

[Show 15 more](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.4.1](https://developer.wordpress.org/reference/since/6.4.1/) | Memoization removed. | 
| [6.4.0](https://developer.wordpress.org/reference/since/6.4.0/) | Memoizes filter execution so that it only runs once for the current theme. | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_template_directory()/?output_format=md#comment-content-1020)
 2.   [Drew Jaynes](https://profiles.wordpress.org/drewapicture/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_template_directory/#comment-1020)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_directory%2F%23comment-1020)
    Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_directory%2F%23comment-1020)
 4. **Include a PHP file**
 5.     ```php
        include( get_template_directory() . '/includes/my_file.php' );
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_directory%2F%3Freplytocom%3D1020%23feedback-editor-1020)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_directory%2F)
before being able to contribute a note or feedback.