Can someone explain how to manage the title tag with PHP?
Printable View
Can someone explain how to manage the title tag with PHP?
What do you mean? You can echo data inside the <title> tag just like any other tag.
yeah, like if my title is "This is my Webpage about _________" php would control the blank part pulling from some variables or somethin
<title>This is my Webpage about <?php echo($title);?></title>
... where $title is the variable to put in.
I would recommend that you use the define function.
Not necessarily... s/he may wish to override it in an include.
then you replace the title tags in require/header.php with:PHP Code:<?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'); ?>
PHP Code:<title><?php if (defined ('TITLE')) {
print TITLE;
} else {
print 'Site Title Not Set.';
}
?></title>
Yes, but what about:Then s/he can't define the title in the body, which is likely to change, and thus likely to set the title.PHP Code:<?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'); ?>