get template directory uri

http://codex.wordpress.org/Function_Reference/get_template_directory_uri


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

Function Reference/get template directory uri

Contents

[hide]
  • 1 Description
  • 2 Usage
  • 3 Parameters
  • 4 Return Values
  • 5 Examples
  • 6 Notes
  • 7 Change Log
  • 8 Source File
  • 9 Related

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 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

  • Uses: apply_filters() Calls 'template_directory_uri' filter on template directory URI path and template name.
  • Uses: get_template()
  • Uses: get_theme_root_uri()

Change Log

  • Since: 1.5.0

Source File

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

Related

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

你可能感兴趣的:(get template directory uri)