板上有一些新功能,最后是一些直观的名称。get_parent_theme_file_uri
和get_theme_file_uri
.
你可以用它代替get_stylesheet_directory_uri()
.
File: wp-includes/link-template.php
4026: /**
4027: * Retrieves the URL of a file in the theme.
4028: *
4029: * Searches in the stylesheet directory before the template directory so themes
4030: * which inherit from a parent theme can just override one file.
4031: *
4032: * @since 4.7.0
4033: *
4034: * @param string $file Optional. File to search for in the stylesheet directory.
4035: * @return string The URL of the file.
4036: */
4037: function get_theme_file_uri( $file = \'\' ) {
4038: $file = ltrim( $file, \'/\' );
4039:
4040: if ( empty( $file ) ) {
4041: $url = get_stylesheet_directory_uri();
4042: } elseif ( file_exists( get_stylesheet_directory() . \'/\' . $file ) ) {
4043: $url = get_stylesheet_directory_uri() . \'/\' . $file;
4044: } else {
4045: $url = get_template_directory_uri() . \'/\' . $file;
4046: }
4047:
4048: /**
4049: * Filters the URL to a file in the theme.
4050: *
4051: * @since 4.7.0
4052: *
4053: * @param string $url The file URL.
4054: * @param string $file The requested file to search for.
4055: */
4056: return apply_filters( \'theme_file_uri\', $url, $file );
4057: }
以及
File: wp-includes/link-template.php
4059: /**
4060: * Retrieves the URL of a file in the parent theme.
4061: *
4062: * @since 4.7.0
4063: *
4064: * @param string $file Optional. File to return the URL for in the template directory.
4065: * @return string The URL of the file.
4066: */
4067: function get_parent_theme_file_uri( $file = \'\' ) {
4068: $file = ltrim( $file, \'/\' );
4069:
4070: if ( empty( $file ) ) {
4071: $url = get_template_directory_uri();
4072: } else {
4073: $url = get_template_directory_uri() . \'/\' . $file;
4074: }
4075:
4076: /**
4077: * Filters the URL to a file in the parent theme.
4078: *
4079: * @since 4.7.0
4080: *
4081: * @param string $url The file URL.
4082: * @param string $file The requested file to search for.
4083: */
4084: return apply_filters( \'parent_theme_file_uri\', $url, $file );
4085: }
217个用于在访问资源时安装它们。ZBe.:
File: wp-content/themes/twentyseventeen/inc/custom-header.php
36: add_theme_support( \'custom-header\', apply_filters( \'twentyseventeen_custom_header_args\', array(
37: \'default-image\' => get_parent_theme_file_uri( \'/assets/images/header.jpg\' ),
38: \'width\' => 2000,
39: \'height\' => 1200,
40: \'flex-height\' => true,
41: \'video\' => true,
42: \'wp-head-callback\' => \'twentyseventeen_header_style\',
43: ) ) );