PDA

View Full Version : Managing Title Tag with PHP



serge4
10-05-2005, 06:46 PM
Can someone explain how to manage the title tag with PHP?

Twey
10-05-2005, 07:43 PM
What do you mean? You can echo data inside the <title> tag just like any other tag.

serge4
10-06-2005, 09:04 PM
yeah, like if my title is "This is my Webpage about _________" php would control the blank part pulling from some variables or somethin

Twey
10-06-2005, 09:14 PM
<title>This is my Webpage about <?php echo($title);?></title>
... where $title is the variable to put in.

dead-poetic
10-06-2005, 11:02 PM
I would recommend that you use the define function (http://us2.php.net/manual/en/function.define.php).

Twey
10-07-2005, 08:47 AM
Not necessarily... s/he may wish to override it in an include.

dead-poetic
10-07-2005, 07:14 PM
<?php define ('TITLE', 'Page Title Here');
//requre the header file
require('require/header.php');
//rest of code here

//require the footer
require('require/footer.php'); ?>
then you replace the title tags in require/header.php with:

<title><?php if (defined ('TITLE')) {
print TITLE;
} else {
print 'Site Title Not Set.';
}
?></title>

Twey
10-07-2005, 08:15 PM
Yes, but what about:
<?php define ('TITLE', 'Page Title Here');

// Start output buffering
ob_start();
// Require the body, which will (try to) set a different title for each page
require('require/body1.php');
$body = ob_get_contents();
// End output buffering
ob_end_clean();

//require the header file
require('require/header.php');

echo($body);

//require the footer
require('require/footer.php'); ?>Then s/he can't define the title in the body, which is likely to change, and thus likely to set the title.