Change PHP title on page-to-page basis

90 Views Asked by At

So let's say I have multiple pages that are structured like so:

<?
    include_once("head.sub.php");
?>

..HTML continues

Logic pertaining to the <title> in head.sub.php.

if (!isset($g5['title'])) {
    $g5['title'] = $config['cf_title'];
    $g5_head_title = $g5['title'];
}
else {
    $g5_head_title = $g5['title']; // 상태바에 표시될 제목
    $g5_head_title .= " | ".$config['cf_title'];
}

This is where it's actually getting the title in head.sub.php.

<title><?php echo $g5_head_title; ?></title>

Below is what I have attempted to change the HTML <title> page-by-page.

<?
    $g5_head_title = 'New Title | example.com';
    include_once("head.sub.php");
?>

However, I have not had much success. Currently, it's using the title from $g5['title']. I want some pages to keep this default title, while others are custom.

1

There are 1 best solutions below

3
On BEST ANSWER

Change the logic to this:


if (isset($customTitle)) {
  $g5['title'] = $customTitle;
  $g5_head_title = $customTitle;
} else if (!isset($g5['title'])) {
  $g5['title'] = $config['cf_title'];
  $g5_head_title = $g5['title'];
}
else {
  $g5_head_title = $g5['title']; // 상태바에 표시될 제목
  $g5_head_title .= " | ".$config['cf_title'];
}

and then you can have this:

<?
    $customTitle = 'New Title | example.com';
    include_once("head.sub.php");
?>