Use multiple custom headers on a WordPress theme

/ Published in: PHP
Save to your folder(s)

The first thing to do is to create header files. Create as many different headers as you want. In this exemple, I have created 3 custom headers from my theme default file header.php, names headercontact.php, headergallery.php and headerdefault.php.

By using the php include() function and WordPress conditional tags, we can define custom headers easily.
Replace the content of your header.php file with the following code:

Copy this code and paste it in your HTML
  1. <?php
  2. if (is_page('contact')){
  3. <?php include(TEMPLATEPATH.'/headercontact.php'); ?>
  4. }
  5. elseif (is_page('gallery')){
  6. <?php include(TEMPLATEPATH.'/headergallery.php'); ?>
  7. }
  8. else {
  9. <?php include(TEMPLATEPATH.'/headerdefault.php'); ?>
  10. }
  11. ?>


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.