Archive

Posts Tagged ‘php’

How to add unique titles in php

February 14th, 2009 ogletree 21 comments

One of the thing I run into the most when evaluating a website for seo is the same title on every page. This can be fixed with a little bit of code. If all the pages are static you just go to each page. If the page is using a header file then you have to make some changes. If they have a lot of static pages with an include file for the header you are still going to have to go and change every page. If you have a lot of data in a database you can just make some changes in the header file. Here is the php code to fix the problem.

Website using header file on a bunch of static pages.

Include File:
<title>
<?php
if($title){echo $title; }else{ echo "Generic Title";}
?>
</title>
 
Static Page
<?php
$title = "Unique Title";
include 'header.inc';
?>

Your still going to have to go to every page and put that on it. This allows you to keep a header file that you can change in one place. If your site is completely dynamic your going to need to add a title field to your database and populate it with Titles. Then use the same if statement on the title tag but echo the title from the db.

Categories: Google Tags: , ,