PHP Tutorial : Dynamic titles for different pages

Very usefull when optimizing your website for search engines, this tutorial will show you how to keep in one single page which you will include in all others, the dynamic titles script for different pages. This will help keep your website on the headlines recommended by every seo guys. We will need to make a variable to get the page, and put an switch & case feature to estabilish the title, then we’ll print the resulted title.

<?php
$page = $_SERVER['PHP_SELF'];

if(isset($page)) {

switch($page) {

case "index.php":
$title = "this is homepage";

break;

case "products":
$title = "products";

break;

case "contact":
$title = "contact";

break;
}
}else{
$title = "default title";
}

print "<title>$title</title>";
?>

Enjoy!

This entry was posted in Usefull PHP and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>