Show different header title depending on page

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Show different header title depending on page

I’ve used this options for different situation and it does work properly. I can use this to specify not only the specific header title, but also to include different style CSS or javascripts based on the specific page or whatever you need included for that page only.

In case you use static pages, I recommend using something like this in your actual page, for example the contact.php file:

And then using that page variable directly into the header.php file as bellow:

This is pretty simple right? It will switch to the specific section of the code and execute it if the $page value is one of the 3 pages, else will use the default part.

Always use a default section just in case you did something wrong and hopefully don’t break the page experience for the user.

Now you can do something much simpler in just the header.php file, this would only work if you actually have a page parameter in your url. For example:

In this case you should just read the request parameter just before the switch part, for example using:

You can also add a bit more assurance and say threat the default section as something invalid / invalid request or bad request in case someone wanted to do something the code should not expect.

That’s about it, happy codding.

Request an article ←