-1

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.

user
  • 45
  • 7
  • 1
    try `$g5['title'] = 'New Title | example.com';` before your `include_once("head.sub.php");` – TKoL Feb 27 '23 at 15:23
  • @TKoL No luck with that, unfortunately. – user Feb 27 '23 at 15:26
  • Is it an option to change the code block starting with `if (!isset($g5['title'])) {`?? Is that logic editable? – TKoL Feb 27 '23 at 15:29
  • @TKoL Yes it is. – user Feb 27 '23 at 15:29
  • 1
    You could try adding another `if` block to match the first one, something like `if (isset($customTitle)) $g5['title'] = $customTitle; $g5_head_title = $customTitle;` And then set $customTitle before your `include` – TKoL Feb 27 '23 at 15:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252163/discussion-between-user-and-tkol). – user Feb 27 '23 at 15:32

1 Answers1

1

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");
?>
TKoL
  • 13,158
  • 3
  • 39
  • 73
  • Currently it shows this as the ``: "`New Title | example.com | example.com`" It's loading the other `" | ".$config['cf_title'];`. Whenever I remove the `else` logic it uses the `#customTitle` only. However, that also affects other functionality. Got any other suggestions on logic? – user Feb 27 '23 at 21:47
  • @user I've made an edit, try that – TKoL Feb 28 '23 at 09:20
  • 1
    This works. So does putting your old `if` logic **following** the previous `if` `else`. – user Mar 01 '23 at 14:25