WebDesign: Header file, but with custom Page titles?

n a picture n a · Apr 28, 2010 · Viewed 12.5k times · Source

I've been using headers to create templates for websites. It's easy, and very convenient for debugging.

I now face the problem of using head BUT with custom page titles. If this is my header.php >

<html>
    <head>
        <title> My Site : ??? </html>
    </head>
<body>


</body>
</html>

I need ??? to be replaced for every page.

Is this possible? If so, how? Thank you. : )

Answer

webbiedave picture webbiedave · Apr 28, 2010

Not knowing more about your file inclusion scheme, the simplest way would be:

page2.php

<?php
$pageTitle = 'Page 2';
include 'header.php';
?>

<div>My content</div>

<?php include 'footer.php'; ?>

header.php

<html>
    <head>
        <title> My Site : <?php echo $pageTitle ?> </title>
    </head>
<body>

footer.php

</body>
</html>