Jump to content

Change Title based on URL


DarkxPunk

Recommended Posts

I will admit it. I prob need someone to do the job for me. PHP is very new to me, most I have made it do is a basic email form following a tutorial. So thank you to anyone who helps me out. It will be a learning experience for me.So I need php to change the title inside the header based on the URL. I know search engines dont read it when you use js so I need to do it in php.Thanks for any help,Michael Snape

Link to comment
Share on other sites

There are several ways to achieve this, heres just one

<?php$pageName = basename($_SERVER['SCRIPT_NAME'], '.php').'.php';    switch ($pageName){case 'currentpage.php':  $title= "Current Page Title";  $description = "this describes the currentpage page";  break;case 'about.php':  $title=  "About Page title";  $description = "this describes the about page";  break;default:  $title=  "";  $description = "";}        ?><!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 $title; ?></title><meta name="description" content="<?php echo $description; ?>" />

Link to comment
Share on other sites

changed slightly, did not require.'php' for file name retrieval.

<?php//retrieve filename from path retrieved by using $_SERVER['SCRIPT_NAME']$pageName = basename($_SERVER['SCRIPT_NAME']);//compare variable $pageName value with those define with each case '....':, if found apply value to specific variable and break (stop going any further), else show default.switch ($pageName){case 'currentpage.php':  $title= "Current Page Title";  $description = "this describes the currentpage page";  break;case 'about.php':  $title=  "About Page title";  $description = "this describes the about page";  break;default:  $title=  "";  $description = "";}        ?>

rest is just applying value of title and description.

Link to comment
Share on other sites

Completely understand. Thank you very much! I also used this (instead of JS which you helped with) to load the navigation bars style, sadly the JS was not working in IE.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...