Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change PHP title on page-to-page basis

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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.

>Solution :

Change the logic to this:


if (isset($customTitle)) {
  $g5['title'] = $customTitle;
  $g5_head_title = $customTitle;
}


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");
?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading