Jump to content

Header.php issue and "programmatic" updating of title and meta data


mmad

Recommended Posts

Guys, I had a developer working on my header.php file contained in all of my webpages of a site we have.  Our issue was that the header include did not allow us to have separate page titles and meta data...like descriptions and keywords.  See below for what they provided.  I have not been able to contact them to see how I can actually implement what the offered as a solution.  Any help is much appreciated.

 

<?php

  $filePath = $_SERVER['SCRIPT_NAME'];

  if (preg_match('/.*\/(.*)/', $filePath,$arrPage)) {

            $page = $arrPage[1] ;

          }

         

  if ($page == "index.php") {

              echo('<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />

                    <meta http-equiv="Content-Language" content="en"/>');

          }elseif($page == "page2.php") {

            // you will type here

          } elseif($page == "page3.php") {

            // you will type here

          }

 

?>

 

Not sure about that code, but what I do for separate page titles is have the title echo out the title of each page.

 

For instance

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title; ?></title>
.
.
.....

would be your header page.

 

Then, on every page, you would start it out like (about.php)

<?php
session_start();

$page_title = 'About Us';
require("header.php");
?>

Then, every time that page is loaded, the title would be About Us

 

 

Hope that helps

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.