0

Now i have the footer and header of the main page copied in every page of my site, is there a way to set it somehow to update on every page each time i modify it on index, or to get it from an external source?

  • 3
    Possible duplicate of [Common Header / Footer with static HTML](https://stackoverflow.com/questions/418503/common-header-footer-with-static-html) – Daniel A. White Jun 16 '17 at 01:31

2 Answers2

0

You can’t do this with plain HTML. You may use jquery or javascript frameworks though.

Follow this solution here: https://stackoverflow.com/a/18712605/3086531

Brxxn
  • 112
  • 1
  • 12
bhar1red
  • 380
  • 2
  • 9
0

For a more advanced approach, you can simply use PHP Includes or Requires.

include ‘filename’;

or

require ‘filename’;

The filename’s will simply be your header and footer pages. I’ll show you an example to get the idea.

Let’s say we have a footer and it looks like this:

<?php
echo “<p>Copyright of Brian. SO 
1994-“.date(“Y”).</p>”;
?>

Now be mindful that, like always, you can add attributes to the paragraph in your footer and header and even call style sheets that can style those paragraphs or whatever you’ve got in you footer or header.

Now, to have your page(s) display the footer or header that you’ve made, and in your case, both; simply use the format shown here:

<html>
<body>

<h1>Welcome to my Homepage!</h1>

<p>Some text.</p>
<p>Some more text.</p>


<?php include ‘footer.php’;?>


</body>
</html>

Now, notice that in my example, my footer file is in a .php format rather than an .html, that’s because my footer example contained a PHP specific function to render the current year. If yours is strictly HTML with a CSS style sheet linked to it, simply type ’footer.html’; or whatever your file name is. The header works the same exact way!

Brxxn
  • 112
  • 1
  • 12