Include Title in < head >

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ccmovies
Forum Newbie
Posts: 15
Joined: Mon Oct 11, 2010 9:14 pm

Include Title in < head >

Post 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!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Include Title in < head >

Post 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>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
ccmovies
Forum Newbie
Posts: 15
Joined: Mon Oct 11, 2010 9:14 pm

Re: Include Title in < head >

Post 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.
Post Reply