1

I have a php include statement for the "head" of my website.

I am using the following code to call head.php...

<?php 
    include '../components/head.php' 
?>

And in my head.php I have the following code...

<head>
    <link rel="stylesheet" type="css" href="/style.css">
    <title>Dummy Code</title>
</head>

How can I make it change the title by having a variable in my page on my page like Dummy Code | About being the title if I have $title = "About" on my webpage.

Is there anyway to do this?

Dummy Code
  • 1,858
  • 4
  • 19
  • 38

1 Answers1

3

They all belong to the global namespace, so you just can do this:

<?php 
    $title = 'about';
    include '../components/head.php' 
?>

head.php:

<head>
    <link rel="stylesheet" type="css" href="/style.css">
    <title>Dummy Code | <?=$title; ?></title>
</head>

But make sure that you understand: this is very simplified code and should not be used on the production projects.

ozahorulia
  • 9,798
  • 8
  • 48
  • 72