How to require specific PHP files for specific templates

I had a similar problem, and posted the question here Using Includes in Templates in Document Head .

And I figured out the solution is to use get_template_part(). From my answer (which I checkmarked as correct; the other answer didn’t work):

The key is to use the get_template_part in your Template at the beginning (after the template header). The file specified in that function must be in your Theme’s root folder, although I think it could also be in the theme’s template folder.

get_template_part('my_custom_functions');

This will do the equivalent of a ‘include’ in a non-WP PHP code. It will ‘include’ the file called my_custom_functions.php .

See my answer in the link above for more info.