get_template_directory_uri()

最后更新于:2021-11-27 00:53:18

get_template_directory_uri()

Retrieves template directory URI for current theme.

响应

(string) URI to current theme’s template directory.

源文件

文件: gc-includes/theme.php

function get_template_directory_uri() {
	$template         = str_replace( '%2F', '/', rawurlencode( get_template() ) );
	$theme_root_uri   = get_theme_root_uri( $template );
	$template_dir_uri = "$theme_root_uri/$template";

	/**
	 * Filters the current theme directory URI.
	 *
	 * @since 1.5.0
	 *
	 * @param string $template_dir_uri The URI of the current theme directory.
	 * @param string $template         Directory name of the current theme.
	 * @param string $theme_root_uri   The themes root URI.
	 */
	return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri );
}
/**
 * Enqueue scripts and styles.
 */
function gcdocs_theme_slug_scripts() {
	// Custom scripts require a unique slug (Theme Name).
	gc_enqueue_script( 'theme-slug-custom-script', get_template_directory_uri() . '/js/custom-script.js', array(), '1.0.0', true );

	/*
	 * To avoid double loading Genericons will not need a slug. Same applies
	 * to all other non-custom styles or scripts.
	 */
	gc_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '1.0.0' );
}
add_action( 'gc_enqueue_scripts', 'gcdocs_theme_slug_scripts' );