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.
Author by
sf_tristanb
CTO @ Y-Proximité (Lyon - France) | @sf_tristanb Symfony developper | Personal project : http://www.seek-team.com
Updated on June 04, 2022Comments
-
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 about 14 yearsIt would be best to see some example code for how your files are structured, otherwise you will get more generic answers.
-
-
sf_tristanb about 14 yearsThanks that was fast ;) $header = "title of my page"; include_once 'header.php'; header // echo ("<title>$header</title>");
-
Joe Day over 11 yearsThat 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.