1

When I've built static sites in the past I've had an includes folder and used php if I've needed to repeat components / HTML over different pages.

I've noticed in Wordpress that this functionality is undertaken with a template-parts folder which seems to do the same thing.

I'm about to start building a custom theme for the 1st time and my question is, is there a reason why I should use template-parts instead of an includes folder, and if I use an includes folder will there be any negatives to this?

Many thanks

  • As long as you let WordPress know where to find things, you can call your folders (sub-directories) anything you want. I use get_template_part('<dir>/<file>'); all the time just remember to leave the .php of the file part. – Matthew Brown aka Lord Matt Sep 13 at 14:55
  • hi @MatthewBrownakaLordMatt that wasn't what I was asking. My question is if I just use a stand php include instead of getting a template part the wordpress way will this work, and more importantly if it does still work is there a reason why I shouldn't do it? – The Chewy Sep 13 at 16:38
  • I think include should work but it would not allow extensibility via child themes and would not then look for the various possible fallbacks. – Matthew Brown aka Lord Matt Sep 13 at 21:22
1

It doesn't matter. It just has to do with standard naming in WordPress because you typically call your "parts" with get_template_part();.

get_template_part(); checks if the file is in the child theme first, then uses the one from the parent theme if it doesn't. It provides a way for you to override template files from the child theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.