Header how to modify title of the page "on the fly"

14,471

Solution 1

Make a variable $page_title. Set it before including the header and in the header have something like:

echo("<title>$page_title</title>");

Solution 2

Set a variable for the title before including the header, then output the variable within the header.

Share:
14,471
sf_tristanb
Author by

sf_tristanb

CTO @ Y-Proximité (Lyon - France) | @sf_tristanb Symfony developper | Personal project : http://www.seek-team.com

Updated on June 04, 2022

Comments

  • sf_tristanb
    sf_tristanb about 2 years

    My header is called as you can imagine, on each pages.

    it means that on each pages i've the same title (bad for SEO)

    Is there a workaround to set pages title outside the header.php ?

    Thanks

    • akamike
      akamike about 14 years
      It would be best to see some example code for how your files are structured, otherwise you will get more generic answers.
  • sf_tristanb
    sf_tristanb about 14 years
    Thanks that was fast ;) $header = "title of my page"; include_once 'header.php'; header // echo ("<title>$header</title>");
  • Joe Day
    Joe Day over 11 years
    That would echo the title tags at the time of the function call, which is after the header was included. This wouldn't solve the original poster's problem.