Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
get_stylesheet_directory_uri() - 检索启用的主题的样式表目录URI - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / get_stylesheet_directory_uri()

get_stylesheet_directory_uri()

检索启用的主题的样式表目录URI


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 4 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "ac5e33dfc440ed9188bdfcdbe4f25e2c" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "3239c45afed7bef4747a209933765d05" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "cb0be4401d17f7a2b11cf4fc4c76f5de" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

directory

stylesheet

uri


返回

(string) 启用的主题的样式表目录URI。


说明

  • 返回的URI不包含结尾斜杠。
  • 这个函数返回一个正确格式的URI;换句话说,它将是一个网络地址(以http:// 开始,或以SSL的https://)。因此,它最适合用于链接,引用额外的样式表,或者可能是最常见的图片。
  • 在使用子主题的情况下,这个函数将返回子主题的目录URI。使用get_template_directory_uri()来避免被子主题覆盖。
  • 如果你想在PHP中引入一个本地文件,使用get_stylesheet_directory()代替。


源码

查看源码 官方文档


更新日志

版本描述
1.5.0开始引入

使用示例

  • 示例1

    如果使用子主题,此函数将返回当前子主题的URL。如果要返回父主题的URL,请使用get_template_directory_uri()。

  • 示例2

    图像(HTML)

    <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/aternus.png" alt="" width="" height="" />
    
    
  • 示例3

    假定–
    网站URL:https://example.com/
    已启用主题文件夹:mytheme

    此函数返回以下字符串:

    https://example.com/wp-content/themes/mytheme

    注:无尾随斜杠(/)

  • 示例4

    使用内部HTML“src”属性时,在函数后添加一些文件时,应转义返回的URL:

    <script async
      type="text/javascript"
      src="<?php echo esc_url( get_stylesheet_directory_uri() . '/dist/main.js' ); ?>">
    </script>