How do I dynamically set the meta tags in an included header from each html page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Adams

    How do I dynamically set the meta tags in an included header from each html page?

    I have a header.php file containing the following code...

    Code:
    ...
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php echo $tpTitle ?></title>
    <meta name="description" content="<?php echo $pgDesc ?>"></meta>
    <meta name="keywords" content="<?php echo $pgKeywords ?>"></meta>
    ...
    In my other .php pages I want to be able to set the variables in the included header file.

    I have:
    Code:
    <?php include("../incl/header.php"); ?>
    <?php
    $tpTitle="Page title";
    $pgHeading="";
    $pgDesc="page description";
    $pgKeywords="page keywords";
    ?>
    
    <body id="courses">
    <?php include("../incl/nav.php"); ?>
    ...
    I know this doesn't set the variables in the required page. Can someone let me know what the format for doing so is?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    It doesn't work like that. You'll have to define the variables before the include.

    Comment

    Working...