A server side language like php is the way to go. A server side language will give you the ability to do what is called a server side include
.
So for example you can create one file called header.php
and place all your code from the opening <html>
tag to whatever else will constantly be at the top of your website. You might want to take this even further and create a footer.php
to put all the code that will constantly be at the bottom.
Example header.php
<!doctype html>
<html>
<head>
<title>My Awesome Website</title>
</head>
<body>
<header>
<nav>
<ul>
<li>Menu Link 1</li>
<li>Menu Link 2</li>
<li>Menu Link 3</li>
</ul>
</nav>
</header>
<div id="main">
Example footer.php
</div><!-- end #main -->
<footer>
My Awesome website's Footer content!
</footer>
</body>
</html>
Now to put them together on our homepage or index.php
Example index.php
<?php include 'header.php'; ?>
<h1>Welcome to my home page!</h1>
<p>This is my super awesome site and I hope you like it!</p>
<?php include 'footer.php'; ?>
The final output sent to the browser would be the following:
<!doctype html>
<html>
<head>
<title>My Awesome Website</title>
</head>
<body>
<header>
<nav>
<ul>
<li>Menu Link 1</li>
<li>Menu Link 2</li>
<li>Menu Link 3</li>
</ul>
</nav>
</header>
<div id="main">
<h1>Welcome to my home page!</h1>
<p>This is my super awesome site and I hope you like it!</p>
</div><!-- end #main -->
<footer>
My Awesome website's Footer content!
</footer>
</body>
</html>