What's more, WordPress gives you two more useful ways to include goodies. First, you can optionally use those functions with an argument for the name: get_header('custom'), for example, will grab a file called header-custom.php. And, if you'd like to include other types of files that don't fit into any of those formats, you can use get_template_part('partname'), which grabs a template called partname.php.
The more PHP-inclined among you may be wondering why WordPress provides these functions when we have a perfectly good include method in PHP. I'm glad you asked. The reason why you might choose the get_ functions over include is because they have some nifty, built-in dummy-proofing. Let's imagine your template needs to use a file called footer-foobar.php, which you'd call on like so:
Let's also imagine that some clumsy but well-meaning user deleted footer-foobar.php. If you'd used include, any page calling on it would show a couple of PHP errors that would tell every visitor that there's no such file or directory, making your theme's user look bad. With get_footer, however, WordPress will first check for footer-foobar.php, then try to include footer.php as a fallback. If footer.php is also missing, WordPress will give up quietly, leaving your poor user's reputation intact. Sweet!
If you really do have a need to use good old PHP includes, WordPress also provides you with constants called STYLESHEETPATH and TEMPLATEPATH for easy use with regular PHP include statements. TEMPLATEPATH is for use with standalone themes, and STYLESHEETPATH is for child themes. You'd use them like so:
Was this article helpful?