在wordpress中排队脚本时get_stylesheet_directory_uri()和get_template_directory_uri()有什么区别 [英] What's the difference between get_stylesheet_directory_uri() and get_template_directory_uri() when enqueuing scripts in wordpress
问题描述
这不是一个严肃的问题.
It's not a serious question.
我通常在 WordPress 中排队脚本时使用 get_stylesheet_directory_uri()
,到目前为止效果很好.
I normally use get_stylesheet_directory_uri()
when enqueuing scripts in WordPress, which worked fine so far.
我只是想知道在 wordpress 中对脚本进行排队时 get_stylesheet_directory_uri()
和 get_template_directory_uri()
之间有什么区别.
I just wonder what's the difference between get_stylesheet_directory_uri()
and get_template_directory_uri()
when enqueuing scripts in wordpress.
根据 WordPress Codex:
get_template_directory_uri
-> 检索模板目录 URI当前主题.get_stylesheet_directory_uri
-> 检索样式表目录 URI当前主题/子主题
get_template_directory_uri
-> Retrieve template directory URI for the current theme.get_stylesheet_directory_uri
->Retrieve stylesheet directory URI for the current theme/child theme
那么,get_template_directory_uri
不能用于子主题吗?
Then, get_template_directory_uri
cannot be used for a child theme?
推荐答案
这两个函数都可以在父主题或子主题中使用.
Both functions can be used in a parent or a child theme.
get_template_directory_uri 将始终引用资产的父主题文件夹.
get_template_directory_uri will always refer to the parent theme folder for assets.
get_stylesheet_directory_uri 将引用资产的当前"主题文件夹(可能是父或孩子,取决于它在哪里被调用).
get_stylesheet_directory_uri will refer to the "current" theme folder for assets (which could be the parent or the child, depending on where it is called).
例如,在子主题中:
// This will point to style.css in child theme
wp_enqueue_style( 'my_child_styles', get_stylesheet_directory_uri().'/style.css' );
// This will point to style.css in the parent theme
wp_enqueue_style( 'my_parent_styles', get_template_directory_uri().'/style.css' );
请注意,如果主题不是子主题,则将其视为父主题.
Note that if a theme is not a child theme, then it is considered a parent theme.
这篇关于在wordpress中排队脚本时get_stylesheet_directory_uri()和get_template_directory_uri()有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!