Skip to content

Instantly share code, notes, and snippets.

@cobbman
Last active December 14, 2015 07:59
Show Gist options
  • Save cobbman/5054943 to your computer and use it in GitHub Desktop.
Save cobbman/5054943 to your computer and use it in GitHub Desktop.
You keep using the same HMTL over and over again to create the same header information on each page, and then one day you realize there must be an easier way. You don't have a CMS set up and it's just a small site with 5-10 HTML pages. Well, put that header into it's own separate 'header.php' file and then on each page in the site, use this to r…
// your header.php file might look something like this (doesn't even have to be betwen <?php ?> statements!
<header>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Store</li>
<li>Contact</li>
</ul>
</nav>
</header>
// just put this where you want the header.php file to go (relative path here)
<?php include 'header.php'; ?>
//You can include other types of files too, such as a text file
<?php include 'article.txt';?>
//COOL TRICK: Lets say header.php might not exist, you can use the @ symbol to hide
the error messages so users won't see that an error happened.
<?php @ include 'header.php' ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment