PHP Includes

You can use PHP to make updating your website layout very quick and easy. Before you begin the tutorial, make sure your web host has PHP support enabled.

Step 1

Take a look at your layout's code. It should look something like this:

<html>
<head>
<title>your site's name</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<body>

<h1>Your Page Title</h1>

Your text goes here.

</body>
</html>

Your coding is obviously going to be longer than the example shown above.

Step 2

Take everything that comes before your content, copy and paste it into Notepad. In this case, you'd be copying this:

<html>
<head>
<title>your site's name</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<body>

Save that as header.txt. It doesn't have to be titled "header", you can name it anything you'd like. Now you have your header and now we need a footer.

Step 3

Take everything that comes after your content, copy and paste it into Notepad. In this case, you'd be copying this:

</body>
</html>

Save that as footer.txt. Just like the header, you can name it anything you'd like.

Step 4

Now you have a header and a footer, upload them onto your website just like you upload the pages of your website.

Step 5

It's time for the longest step. Convert every page to a PHP file. For example, if you have a page titled "index.html", you'd rename it to "index.php".

On every page, remove everything except for the content. Insert the following code at the top of your pages (before your content).

<? include("header.txt") ?>

Insert the following code at the bottom of your pages (after your content).

<? include("footer.txt") ?>

All of your pages should look like this:

<? include("header.txt") ?>

<h1>Your Page Title</h1>

Your text goes here.

<? include("footer.txt") ?>

You're done. From now on, when you want to edit your layout, you just edit two files, the header and footer files (and your CSS document if you have one).