WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the theme-check plugin to check my theme for errors and recommendations, I'm using get_template_part() in theme files like header.php and index.php but in functions.php I'm using include_once() theme-check is not pointing at these, it's pointing at include_once used in a widgets.php file which is included in functions.php

my question is should we use get_template_part() instead of all include_once() and include() or just use it for getting frequently used markup only ? I know it's only recommended to use get_template_part() but I like to follow best practices and recommendations.

thanks in advance.

share|improve this question
Looking at plugin code from some of the core contributors and other WP experts, I've never seen get_template_part() used this way although it doesn't seem wrong. The point of the function, though, is to reuse parts of code which would differentiate it from the need to include a file once. I'm interested in seeing what others have to say about this. – developdaly Apr 7 '12 at 14:23
Those are recommendations, if you're not including template part it's more simple to use include_once(). – Mamaduka Apr 7 '12 at 14:56
up vote 3 down vote accepted

Your functions.php doesn’t create output, so you should use locate_template().


locate_template( 'php/functions.nav-menu.php', TRUE, TRUE );

You’ll find this function in wp-includes/theme.php. The first parameter is the file path relative to the theme root, the second tells WordPress to load it (or not), and the third to load it just once.

Now a child theme can override the file by just placing a file with the same name to the same place in its own theme root.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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