After many years and completing the great Html and Css course on freecodecamp I am trying again to make some webpages.
I want a repeating header and menu on all the pages (I will need a lot of pages). Of course I could save this as a text template and use it again and again. But what if something changes? Do I have to change all my pages if for example I add something to the menu?
Thanks for your help!
1 Like
Hi @igenjanneke. This can be easily achieved using PHP or jQuery.
Using PHP:
- Create a
header.html
file. - Now create a
index.php
file which contains main content. - In the
index.php
file, place<?php include 'header.html' ?>
- Now visit the
index.php
file via your localhost and check if it works or not. - If you want to edit the header, you can edit the
header.html
file and then it will be updated everywhere.
Using jQuery:
Note that if you’re doing this with PHP, you need a local server (XAMPP, MAMPP, etc.) as PHP is a server side language.
1 Like
Thank you so much for your quick reaction. This is what I used many years ago, but I was not sure if it was still the way to do it.
1 Like
that doesn’t necessarily work, php is a server side language
2 Likes
I meant check it via his localhost server.
1 Like