Jump to content

Have Each Page Title in the Header?


chaseman

Recommended Posts

I have a header.php, which I include in all my pages, but I'd like to have an individual title for all pages for better SEO - how can I do that?

 

Explanation:

 

header.php

<!DOCTYPE>
<head>
<title>MyWebsite </title>
</head>
<body>

 

 

And I would like to have something like this:

 

header.php

<!DOCTYPE>
<head>
<title>MyWebsite | $InsertPageTitle </title>
</head>
<body>

 

 

And then:

 

example.php

include('header.php');
$InsertPageTitle = "Contact Form";

 

 

 

I tried this exact method, unfortunately it didn't work, so how can I make it work?

 

Thanks

Link to comment
Share on other sites

<!DOCTYPE>
<head>
<title>MyWebsite | <?php $InsertPageTitle ?> </title>
</head>
<body>

 

Have a crack at that buddy. You need to jump into php so the browser (or whatever is creating the page) knows that it's in fact a php variable that you want, not just the text that read $InsertPageTitle.

Denno

 

Link to comment
Share on other sites

You need to define the variable before you include the file that will use it.

 

It took me a minute to understand what you meant, so I though I would post some code to illustrate your meaning, so it's easy for the OP and anyone else to see what to do.

example.php

 

//declare the variable
$InsertPageTitle = "Contact Form";
//before you use it in the following file
include('header.php');

 

Correct me if I'm wrong, but I think this is what Pikachu2000 is referring to?

 

Denno

 

Link to comment
Share on other sites

You need to define the variable before you include the file that will use it.

This was the mistake I was doing.

 

I did the <?php echo ?> thing, I just forgot to do it in the example, it was late night, sorry about that. But the mistake I was doing was:

 

include('header.php');
$pagetitle = "Contact Form"; 

 

Instead it should be:

$pagetitle = "Contact Form"; 
include('header.php');

 

I just tried it and now it works, thanks to all.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.