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

The basic theme - in fact every theme I've looked at - uses get_header() to include the header file, but I don't see any reason for doing so.

What's are the advantages of using get_header() instead of a simple include('file.php')?

share|improve this question
I know this is well off-topic, but too often I see include('some-file.php'); - there's no need for parenthesis, it's a language construct! include 'some-file.php'; does the job just fine, plus IMO looks neater too ;) – TheDeadMedic Dec 11 '10 at 16:17

Using generic function means throwing out layer of WP API:

  • get_header hook would be gone;
  • compatibility with fetching different headers by name ("header-{$name}.php") would be gone;
  • usage of locate_template() would be gone, which likely would destroy compatibility with child themes.

You can always look at source to see what exactly function does.

WordPress uses own function not just-because. It is usually for concrete compatibility or functionality reasons.

share|improve this answer
I've been calling alternative headers with a php include statement instead of get_header and this explains why I have been getting some strange behavior. – matt Dec 11 '10 at 16:52

The main reason is that you can hook into get_header, which means you can do header-y stuff in a child theme, or a separate function file without needing to edit the parent theme files.

You don't want to edit parent theme files because it makes upgrading them harder, as you then need to reapply your changes. If those changes are isolated in a child theme it makes upgrading MUCH easier

share|improve this answer

You can also use the get_header() function to get a different header file. Name the custom header file header-whatever.php, then use


and WP will use the header-whatever.php file instead of header.php.

Note that the syntax is wonky - you'd think you should put the filename in there instead, but no - you need the name after the hyphen only. I want that hour of my life back now :(

share|improve this answer
ohh thx! damn hyphen. maybe it will lighten your day when you know you saved someone a couple of hours? :) – user7589 Aug 3 '11 at 14:47

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.