Saeid Ghaferi
Saeid Ghaferi

Reputation: 123

multiple page titles with one header file

i have one file for the header which is included on all of my other pages. I was wondering how i could have different page titles for with the same page header. I am using PHP and MySql. Thanks!

Upvotes: 2

Views: 3565

Answers (3)

Rob Sedgwick
Rob Sedgwick

Reputation: 5226

break out the title tag from the include and place it in page, seems to be forcing you to make workarounds

Upvotes: 1

Hope4You
Hope4You

Reputation: 1947

On every specific page, add $pgName = 'Page Title'; to title each page. Then after this code, include() the header as normal. In the header file, add this in the <head> tags:

<title><?php if(isset($pgName) && is_string($pgName)){echo $pgName;}else{echo 'Default title';} ?></title>

Upvotes: 6

Ignas
Ignas

Reputation: 1965

Store the title in a variable e.g.

$title = 'Main title';
if($page == 'this page has a different title') {
  $title = 'A different title';
}
include 'header.php';

In header.php set

<head>
  <title><?php echo $title; ?></title>
...

Upvotes: 4

Related Questions