I have a PHP website, where it contains header.php
in the includes
. And I include this header.php
in many other .php pages of my website. The header.php
already contains <head>
tags which are necessary for every page. And I want to add different meta title and description for each page separately.
So when the index.php
loads it have two tags. And when I test the website with lighthouse Audit in Chrome. My SEO say no metadata found in the HTML document.
So please help me to combine those two tags.
2
Answers
Includes have access to all variables defined before the file is included.
So you can set variables for the title and description in the pages where you want to use differing ones and then access them in the included file. Roughly:
Then, in header.php
You either have to remove the
<head>
tags fromheader.php
, or put variables in it and set them before you include it.So,
header.php
would look like this:and an outer file would look like this (for example):