$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Loading files for theme and child theme (Require)|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Loading files for theme and child theme (Require)

matteradmin10PV0评论

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
Share Improve this question asked Dec 14, 2018 at 11:58 user145078user145078 3
  • 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
Add a comment  | 

1 Answer 1

Reset to default 0

get_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() and get_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.

Post a comment

comment list (0)

  1. No comments so far