在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

查看:34
本文介绍了在wordpress中排队脚本时get_stylesheet_directory_uri()和get_template_directory_uri()有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是一个严肃的问题.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆