Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get template directory uri

This page redirects to an external site: https://developer.wordpress.org/reference/functions/get_template_directory_uri/

Description

Retrieve template directory URI for the current theme. Checks for SSL.

Note: Does not return a trailing slash following the directory address.

In the event that a child theme is being used, the parent theme directory URI will be returned. get_template_directory_uri() should be used for resources that are not intended to be included in/over-ridden by a child theme. Use get_stylesheet_directory_uri() to include resources that are intended to be included in/over-ridden by the child theme.

Usage

Use the URI <?php get_template_directory_uri(); ?>

Output the URI <?php echo get_template_directory_uri(); ?>

Parameters

None.

Return Values

uri (string) 
Template directory URI.

Examples

Using get_template_directory_uri() to enqueue a script with the correct path

<?php
function my_scripts_method() {
	wp_enqueue_script(
		'custom_script',
		get_template_directory_uri() . '/js/custom_script.js',
		array('jquery')
	);
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
?>

Notes

Change Log

Source File

get_template_directory_uri() is located in wp-includes/theme.php.

Related

Theme paths: get_template(), get_template_directory(), get_template_directory_uri(), get_theme_roots(), get_theme_root(), get_theme_root_uri(), get_stylesheet(), get_stylesheet_uri(), get_stylesheet_directory(), get_stylesheet_directory_uri(), get_bloginfo(), get_theme_file_uri(), get_theme_file_path()

See also index of Function Reference and index of Template Tags.