skip to Main Content

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


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

    $title = "Some page title";
    $desc = "Page description";
    include 'header.php'
    

    Then, in header.php

    if($title) {
       // output this variable as the page title
    } else {
       // no new title supplied so use the default one
    }
    
    // repeat for description
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search