Page 1 of 1

Include Title in < head >

Posted: Sun Feb 13, 2011 7:58 pm
by ccmovies
Hello! I am making a site with PHP. I have separated the header into it's own file and used the "include" PHP feature to "fetch" it, sorta like Wordpress. The only problem is I want to change the <title> element for each page. How can I do this?

I was thinking something like this: inside the index.php, contact.php, etc put some PHP code that says "this is the title of the page." Then in the header.php inside the <title> tag have a PHP code that basically looks for the "title of the page" and echos it.

Any help would be appreciated. I will be on the forum and will reply fast. Thanks!

Re: Include Title in < head >

Posted: Sun Feb 13, 2011 8:20 pm
by s.dot
Like this:

foo.php

Code: Select all

$title = 'my page title';
require 'header.php';
header.php

Code: Select all

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

Re: Include Title in < head >

Posted: Sun Feb 13, 2011 8:23 pm
by ccmovies
s.dot wrote:Like this:

foo.php

Code: Select all

$title = 'my page title';
require 'header.php';
header.php

Code: Select all

<html>
<head>
<title><?php echo $title; ?></title>
</head>
YEAH!! Thank you :D

I only know a little PHP (mostly Wordpress tags) so I need to learn more and more.