How and Why Include Files Improved My Webbie Life
Posted by Anna Belle on 16 May 2007 at 05:36 pm | Tagged as: Church Websites
For years I’d hear other webmasters rave about the wonders of “include files” (or “Server Side Includes,” as they once were known). It made a certain amount of sense, but somehow I never got around to using them. Then I inherited a site that had includes. Even though those include files were rather a mess, I started to catch on to how powerful and simple they were. Ever since, they’ve been one of my most important webmaster tools. I hope they are for you too. But if not, here’s what they are, why I think they’re so great, and how best to use them.
What Is an “Include File”?
The concept is wonderfully simple. It’s a computer file whose sole purpose is to be part of other computer files. A great example is a footer. Let’s say you have a church website that’s 100 pages. You want every page to have the address, a copyright statement and the office email address on it. You can either code that into all 100 pages or have all 100 pages have one line of code that calls file #101 — the footer.
Next imagine that the office email address starts being spammed and is changed. In the first scenario, you have to update and upload all 100 files, plus test a few pages. In the second scenario, you change the one footer file, upload it and test a few pages. Perhaps the first scenario isn’t that hard for you. You might know how to do global updates. That’s the kind of reasoning that stopped me for a long time, but I promise if your site is more than a few pages, it’s worth changing your practices.
Why Use Includes?
- They save time – lots of it in my experience.
- They are easy to learn and use.
- They reduce errors.
- It’s easier to do site-wide changes.
- Thus they make your site more extensible.
- With repetitive code removed, it’s easier to see core page code.
In other words, they are simple and thus elegant.
When & How to Use an Include
While the principle is universal, the way it’s done varies. Includes aren’t part of HTML, so it depends on what other tools you have available. Back in the early days of the web, SSI was developed for this purpose, but it’s not used much anymore. I use PHP, and here’s what a typical include call looks like:
<?php include “footer.php”; ?>
If I’m being fancier it might look more like this:
<?php @require_once($RootPath . “inc/footer.php”); ?>
The footer.php file itself looks something like:
<div id=”footer”>
<p>1808 Woodmont Blvd. · Nashville, Tennessee 37215<br />
Phone: 615-383-5760 · Fax: 615-383-5785<br />
<a href=”mailto:office@firstuunashville.org”> office@firstuunashville.org</a><br />
Copyright © 2000-<?php echo date(“Y”); ?> First Unitarian Universalist Church of Nashville</p>
</div>
</body>
</html>
To set them up initially, I code a few pages of a new site or redesign, get them working, and then extract the include files from them.
When to Use Includes
Includes are great for chunks of code that repeat on many pages. The likely suspects are:
- Headers
- Footers
- Navigational Elements
- Database connections
Once you’ve got them going, it’s a breeze to do things such as add a Google Analytics script to the footer. Update one file, and you’re set. Even better, you know you’re set. You’re not going to accidentally overlook pages. It’s a beautiful thing.
Do you have other tips or uses for includes? I’d love to hear.

[...] the one step that can be problematic. If you have easy access to your site’s code and host, and use include files, it’s a breeze. You just copy and paste it into your footer include and upload that file. Even if [...]