WordPress “include TEMPLATEPATH” or?

Long answer short: the absolute-best answer, for template-part files in a subdirectory, is to use locate_template()

I would recommend referencing the stylesheet path for template file includes, so that those template part files can be easily over-ridden by Child Themes. So, ideally, you should use get_stylesheet_directory_uri().

Some differences/explanation of all the functions listed by @kaiser:

  • get_stylesheet_directory_uri()/get_template_directory_uri() return a URL
  • get_stylesheet_directory()/get_template_directory() return a file path
  • All four of the *get_*_directory_*() functions perform SSL checking
  • TEMPLATEPATH/STYLESHEETHATH are simple constants, return a file path, and do not perform SSL checking

So, the four get_*_directory_*() functions are preferred to using TEMPLATEPATH/STYLESHEET; however, they aren’t really intended for locating template part files in subdirectories. In such a case, the best option is to use locate_template() directly. (See here for a great writeup and comparison of all of the above options.)

Leave a Comment