Reputation: 215
I am developing a website with oure PHP and HTML on an Apache server. No CMS.
All of my website's pages from the main directory and its subdirectories call one header.php
file.
I have now run into an issue with all of the page <title>
's, as these are obviously defined in the header, so now I don't know how to set a different title for each page.
Can anyone help?
Upvotes: 1
Views: 875
Reputation: 1265
The simplest way to do this is to have a variable that you set on the main page, before you include the header.php file, and then in the header.php file, use that title.
page.php
<?php
$title = "My Title";
include "header.php";
header.php
<title>
// Default Title will be set if you forget to set the $title variable in page.php
<?php echo isset($title) ? $title : "Default Title"; ?>
</title>
Upvotes: 3
Reputation: 4669
What I usually do is have the title tag like this:
<title><? echo $titleIs ?></title>
Then, on each page, before the header include, set the title:
<? $titleIs='Page Title' ?>
Upvotes: 1