admin管理员组文章数量:1130349
There seems to be so many options which one should i go for..it's really confusing? I have used get_template_directory(). What i want is to use a function that works best with child theme and that should work alone if no child theme is used..pls help
- get_theme_file_uri()
- get_parent_theme_file_uri()
- get_theme_file_path()
- get_parent_theme_file_path()
- get_template_directory()
- TEMPLATEPATH
There seems to be so many options which one should i go for..it's really confusing? I have used get_template_directory(). What i want is to use a function that works best with child theme and that should work alone if no child theme is used..pls help
- get_theme_file_uri()
- get_parent_theme_file_uri()
- get_theme_file_path()
- get_parent_theme_file_path()
- get_template_directory()
- TEMPLATEPATH
1 Answer
Reset to default 0get_theme_file_uri(), get_theme_file_path(), get_parent_theme_file_uri() and get_parent_theme_file_path() are relatively new (introduced in WordPress 4.7) functions that have a couple of significant advantages over using get_template_directory().
get_theme_file()andget_theme_file_path ()allow you to reference files in your theme in a way that allows them to be replaced by a child theme. This lets you do things like allow images to be replaced, which wasn't previously possible (without a custom function).- They are all filterable, which allows child themes and plugins to replace them with files either outside a theme, or with files that aren't in the same directory as they were in a parent theme. The filter would also let you prevent the inclusion of a file entirely.
The functions that end in _path() return the path to the files, so would be used for including files for use on the server, while the functions ending in _uri() return the URL to the file, for use on the front-end.
The _parent_theme_ functions let you reference files without letting them be replaced by a child theme.
Since the introduction of these functions the only reason you would use the template_directory or stylesheet_directory functions would be to just get the URL or path to the directory itself.
You shouldn't need to ever use the TEMPLATEPATH constant.
There seems to be so many options which one should i go for..it's really confusing? I have used get_template_directory(). What i want is to use a function that works best with child theme and that should work alone if no child theme is used..pls help
- get_theme_file_uri()
- get_parent_theme_file_uri()
- get_theme_file_path()
- get_parent_theme_file_path()
- get_template_directory()
- TEMPLATEPATH
There seems to be so many options which one should i go for..it's really confusing? I have used get_template_directory(). What i want is to use a function that works best with child theme and that should work alone if no child theme is used..pls help
- get_theme_file_uri()
- get_parent_theme_file_uri()
- get_theme_file_path()
- get_parent_theme_file_path()
- get_template_directory()
- TEMPLATEPATH
-
And what is the problem with
get_template_directory()? – kero Commented Dec 14, 2018 at 12:01 - @kero ..as coding requirement mentions..It is recommended that the following WordPress 4.7+ functions be used, as they greatly improve the child theming capabilities of the theme:get_theme_file_uri() get_parent_theme_file_uri() get_theme_file_path() get_parent_theme_file_path() – user145078 Commented Dec 14, 2018 at 12:06
- @kero i have no problem with get_template_directory()..i think it won't allow overriding...not sure if any of other functions as advantage over it. – user145078 Commented Dec 14, 2018 at 12:10
1 Answer
Reset to default 0get_theme_file_uri(), get_theme_file_path(), get_parent_theme_file_uri() and get_parent_theme_file_path() are relatively new (introduced in WordPress 4.7) functions that have a couple of significant advantages over using get_template_directory().
get_theme_file()andget_theme_file_path ()allow you to reference files in your theme in a way that allows them to be replaced by a child theme. This lets you do things like allow images to be replaced, which wasn't previously possible (without a custom function).- They are all filterable, which allows child themes and plugins to replace them with files either outside a theme, or with files that aren't in the same directory as they were in a parent theme. The filter would also let you prevent the inclusion of a file entirely.
The functions that end in _path() return the path to the files, so would be used for including files for use on the server, while the functions ending in _uri() return the URL to the file, for use on the front-end.
The _parent_theme_ functions let you reference files without letting them be replaced by a child theme.
Since the introduction of these functions the only reason you would use the template_directory or stylesheet_directory functions would be to just get the URL or path to the directory itself.
You shouldn't need to ever use the TEMPLATEPATH constant.
本文标签: Loading files for theme and child theme (Require)
版权声明:本文标题:Loading files for theme and child theme (Require) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749099395a2315758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


get_template_directory()? – kero Commented Dec 14, 2018 at 12:01