CCode for Artists - Miles DeCoster

Custom page titles in a common page header file.

PHP includes are a great way to reuse common page parts like headers and footers. Since the header includes the page title, it would also be nice to change the title of each page as necessary. To do that we assign the page title to a PHP variable in each file that includes the header and use the same variable in the header file to assign the variable to the title element.

In the content file:

<?php $page_title="Code for Artists - PHP custom titles"; ?>
<?php include('cfa-header.php'); ?>
In the cfa-header.php file:
<title><?php echo($page_title); ?></title>