Skip navigation
Tyssen Design — Brisbane Freelance Web Developer
(07) 3300 3303

How do I include code on every page?

By John Faulds /

Variations on this question can include:

  • Can CSS insert content onto a page?
  • How do I update the content of multiple pages from a single file?
  • How can I get CSS to behave like frames?

The answer to all these questions is Server Side Includes (SSI).

With SSI (or PHP includes), you can create a piece of code that is to be repeated in multiple locations and place it in a single file which is then linked to other pages. When you want to update something, you don't have to edit every page, you just edit once.

So how do they work?

First create the code that you want to repeat on other pages. This usually involves something like your navigation or a footer, e.g.:


<p>© Tyssen Design</p>
				

Save that as footer.htm (the file extension is not important - it can be .htm, .html, .inc, .txt, .asp, .php - as the contents of the include are parsed by the page that it is called into).

The type of page you are working with will determine which type of include you need to use. ASP, PHP, JSP and Coldfusion pages all have their own different methods of calling includes. (If your site isn't made with any scripting languages, you will need to ensure that your server is configured to serve SSI correctly.)

ASP/HTML


<!--#include virtual="/footer.htm" -->
<!--#include file="../footer.htm" -->
				

The first example is for absolute paths and the second is for relative paths.

PHP


<?php include("/footer.htm") ?>
				

JSP


<jsp :include page="/footer.htm" />
				

Coldfusion


<cfinclude template="/footer.htm">
				

You then just place your include on your page where you want it to appear.

Includes can have as much or as little information in them as you want. Their main feature is the centralising of code in a single location, thereby making site maintenance much easier.