Should we use get_template_part() in functions files instead of include_once?

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

Example:

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.

Leave a Comment