I have a site created in php, the header tags are loaded in two separate files. One loads for the front page, so I get one set of tags for that, and the other loads for all other pages. This means that I can only optimise one set of keywords for the front page and one set for all the other pages.

Given that the same header file loads with the same tags for all pages other than the front page how can I set dynamic tags which are specific to the page loading but doesn’t look fishy to the search engines and in particular the most holy Google?
Thanks in advance for your assistance?

9 Years
Discussion Span
Last Post by jreseo

First, if the content of your header tags (I assume you mean title, meta description and meta keywords) match the body content of the page, Google will not consider this "fishy", and in fact this is a best practice. Also, having all the title/meta tags duplicated on your inner pages is definitely not optimal. Given the leverage title tags have, you should find a way to make them unique across your site and match the content of each page.

If you are using PHP, you should be able to control what is shown for title/meta tags from the loading module (each page module), even if you are using a header module of some sort.

One technique is to use global variables. Just set up globals for the title, meta description and meta keywords, set those in the module that loads the page content before the include of the header module, and have the header module use those variables to set the tags.

For example, in the page module, use something like:
global $pagetitle;
global $pagedesc;
global $pagekeyw;
$pagetitle="This is a unique title for this page";
$pagedesc="This is a meta description for this page";
$pagekeyw="kw1, kw2, kw3";
include("myheader.php"); // include the header

In the header module, just use the globals:
global $pagetitle;
global $pagedesc;
global $pagekeyw;
echo "<title><?echo $pagetitle;?></title>";
echo "<meta name="description" content="<?echo $pagedesc;?>" />";
echo "<meta name="keywords" content="<?echo $pagekeyw;?>" />";

Technically the variables don't have to be globals with includes, but if you are using functions then you will need to declare them.

Another technique is to set a variable with the page name in the calling page module, and use a table lookup in your header module to get the title/meta content. Same idea, basically.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.