Change Title with include [closed]

1

I have the title of the site in a separate file and I have inserted it with include, therefore the title of all sections of my site are the same. Is there any way to apply a different one for each section? Or the only way would be to take out the manual input one by one?

    
asked by Paco Zevallos 09.03.2017 в 03:49
source

1 answer

1

To avoid that all sections have the same title you must replace with variables php

He explained

Normally I usually divide the pages with PHP in 3/2 parts.

1 - Header where it included (title, navigation menu, etc.)

2 - Footer

Now from the Index.php page or another page, I start calling the Header and the Footer.

Example:

<?php
include "template/header.php";
?>

// Contenido de la página



<?php
include "template/footer.php";
?>

In the template header.php you must replace the text of title with a PHP variable

Example:

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

Now above the include of the header.php create the value of the variable in this case the title of the page.

$title = "Hola Mundo";

Complete example

<?php
 $title = "Hola Mundo";
?>

<?php
include "template/header.php";
?>

// Contenido de la página



<?php
include "template/footer.php";
?>
  

Remember to replace the common text of title with the php

    
answered by 09.03.2017 в 04:41