Hi, i have split the header and footer of my website into includes. My website has 5 pages and i want to use different <meta> and <title> tags on each of the 5 pages. Considering i only have one header.php which is included on each page - i was thinking that i could use an if statement to determine what code needs to be displayed in the header on each page. I am not sure how to do this but i am thinking that i need something like IF $filename = index.php { display this code } I do not have much experience with php so i was hoping that some of you experts could help, thanks in advance
The simplest method is on each page before including the header section set the name of page as follows index.php file <?php $filename = "index.php"; include('header.php'); // then include your header section ?> PHP: header.php file <?php if ($filename == 'index.php') { ?> <meta keyword="index"> <meta description=""> <?php } else if ($filename == 'login.php') { ?> <meta keyword="login"> <meta description=""> <?php } ?> PHP:
Thanks for the reply... Here is what i have but i just get a blank page now... can anyone see what is wrong: --- index.php <?php $filename = "index.php"; ?> PHP: --- head.php <?php } else if ($filename == 'signs-banners.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Signs and Banners </title> <meta name="description" content="Professional Sign and Banner Design and Installation in Wales" /> <meta name="keywords" content="Commercial business", "Vinyl", "Graphics", "Designs", "Banners", "Signs", "Sign company", "Sign makers", “Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> <?php } else if ($filename == 'vehicle-livery.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Vehicle Livery </title> <meta name="description" content=" Quality Vehicle Livery in Wales " /> <meta name="keywords" content="Professional", "Free Quote", "van", "lorry", "vinyl printing", "Installation", "Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> <?php } else if ($filename == 'colour-printing.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Full Colour Printing </title> <meta name="description" content="Full Colour Printing, from Design to Installation" /> <meta name="keywords" content="Full Colour Printing", "Vinyl", "Stationary", "Graphic Design", "Board Promotions", "Free Quote", "Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> <?php } else if ($filename == 'design.php') { ?> <title>Eagle Signs Wales – Design and Installation of Full Colour Signs and Banners </title> <meta name="description" content="Professional Sign and Banner Design and Installation West Wales" /> <meta name="keywords" content="Full Colour Printing", "Vinyl", "Stationary", "Graphic Design", "Board Promotions", "West Wales", "Designs", "Designer", "Vehicle Printing", "Print", "Sign Makers", "Fleet Livery" /> <?php } ?> <?php } else if ($filename == 'contact.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Carmarthen, Pembrokeshire </title> <meta name="description" content="Free Online Quote for Sign Printing in Wales" /> <meta name="keywords" content="Print", "Sign Makers", "Sign Company", "Graphic Designs", "Free Online Quote", "Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> PHP:
--- index.php <?php //or: $filename = $_SERVER['PHP_SELF']; $filename = "index.php"; include("head.php"); ?> PHP: --- head.php <?php if ($filename == 'index.php') { ?> <meta keyword="index"> <meta description=""> <?php } else if ($filename == 'signs-banners.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Signs and Banners </title> <meta name="description" content="Professional Sign and Banner Design and Installation in Wales" /> <meta name="keywords" content="Commercial business", "Vinyl", "Graphics", "Designs", "Banners", "Signs", "Sign company", "Sign makers", “Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> <?php } else if ($filename == 'vehicle-livery.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Vehicle Livery </title> <meta name="description" content=" Quality Vehicle Livery in Wales " /> <meta name="keywords" content="Professional", "Free Quote", "van", "lorry", "vinyl printing", "Installation", "Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> <?php } else if ($filename == 'colour-printing.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Full Colour Printing </title> <meta name="description" content="Full Colour Printing, from Design to Installation" /> <meta name="keywords" content="Full Colour Printing", "Vinyl", "Stationary", "Graphic Design", "Board Promotions", "Free Quote", "Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> <?php } else if ($filename == 'design.php') { ?> <title>Eagle Signs Wales – Design and Installation of Full Colour Signs and Banners </title> <meta name="description" content="Professional Sign and Banner Design and Installation West Wales" /> <meta name="keywords" content="Full Colour Printing", "Vinyl", "Stationary", "Graphic Design", "Board Promotions", "West Wales", "Designs", "Designer", "Vehicle Printing", "Print", "Sign Makers", "Fleet Livery" /> <?php } ?> <?php } else if ($filename == 'contact.php') { ?> <title>Eagle Signs Wales - From Design to Installation, Carmarthen, Pembrokeshire </title> <meta name="description" content="Free Online Quote for Sign Printing in Wales" /> <meta name="keywords" content="Print", "Sign Makers", "Sign Company", "Graphic Designs", "Free Online Quote", "Carmarthenshire", "Pembrokeshire", "Llanelli", "West Wales" /> <?php } ?> PHP:
Here's a way to do it with allot less code: <? switch (basename($_SERVER['SCRIPT_FILENAME'])) { case "index.php": $title = ""; $description = ""; $keywords = "index"; break; case "signs-banners.php": $title = "Eagle Signs Wales - From Design to Installation, Signs and Banners"; $description = "Professional Sign and Banner Design and Installation in Wales"; $keywords = "Commercial business, Vinyl, Graphics, Designs, Banners, Signs, Sign company, Sign makers, “Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "vehicle-livery.php'"; $title = "Eagle Signs Wales - From Design to Installation, Vehicle Livery"; $description = "Quality Vehicle Livery in Wales"; $keywords = "Professional, Free Quote, van, lorry, vinyl printing, Installation, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "colour-printing.php"; $title = "Eagle Signs Wales - From Design to Installation, Full Colour Printing"; $description = "Full Colour Printing, from Design to Installation"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, Free Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "design.php"; $title = "Eagle Signs Wales – Design and Installation of Full Colour Signs and Banners"; $description = "Professional Sign and Banner Design and Installation West Wales"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, West Wales, Designs, Designer, Vehicle Printing, Print, Sign Makers, Fleet Livery"; break; case "contact.php"; $title = "Eagle Signs Wales - From Design to Installation, Carmarthen, Pembrokeshire"; $description = "Free Online Quote for Sign Printing in Wales"; $keywords = "Print, Sign Makers, Sign Company, Graphic Designs, Free Online Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; } ?> <title><?=$title?></title> <meta name="description" content="<?=$description?>" /> <meta name="keywords" content="<?=$keywords?>" /> PHP:
Cool, thanks... what do i need to add to your code to make a generic general case... let's say i haven't declared a set of meta tags for certain pages... would like your code to just use a standard default case if it a page doesn't find a case that matches it's name, thanks again to all who have helped
Here you go, the default is now setup at the bottom: <?php switch (basename($_SERVER['SCRIPT_FILENAME'])) { case "index.php": $title = ""; $description = ""; $keywords = "index"; break; case "signs-banners.php": $title = "Eagle Signs Wales - From Design to Installation, Signs and Banners"; $description = "Professional Sign and Banner Design and Installation in Wales"; $keywords = "Commercial business, Vinyl, Graphics, Designs, Banners, Signs, Sign company, Sign makers, “Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "vehicle-livery.php'"; $title = "Eagle Signs Wales - From Design to Installation, Vehicle Livery"; $description = "Quality Vehicle Livery in Wales"; $keywords = "Professional, Free Quote, van, lorry, vinyl printing, Installation, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "colour-printing.php"; $title = "Eagle Signs Wales - From Design to Installation, Full Colour Printing"; $description = "Full Colour Printing, from Design to Installation"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, Free Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "design.php"; $title = "Eagle Signs Wales – Design and Installation of Full Colour Signs and Banners"; $description = "Professional Sign and Banner Design and Installation West Wales"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, West Wales, Designs, Designer, Vehicle Printing, Print, Sign Makers, Fleet Livery"; break; case "contact.php"; $title = "Eagle Signs Wales - From Design to Installation, Carmarthen, Pembrokeshire"; $description = "Free Online Quote for Sign Printing in Wales"; $keywords = "Print, Sign Makers, Sign Company, Graphic Designs, Free Online Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; default: $title = "Default Title"; $description = "Default Description"; $keywords = "Default Keywords"; break; } ?> <title><?=$title?></title> <meta name="description" content="<?=$description?>" /> <meta name="keywords" content="<?=$keywords?>" /> PHP:
One thing i don't understand about your code is that you a mixture of : and ; after the case... which is the correct symbol <?php switch (basename($_SERVER['SCRIPT_FILENAME'])) { case "index.php": $title = ""; $description = ""; $keywords = "index"; break; case "signs-banners.php": $title = "Eagle Signs Wales - From Design to Installation, Signs and Banners"; $description = "Professional Sign and Banner Design and Installation in Wales"; $keywords = "Commercial business, Vinyl, Graphics, Designs, Banners, Signs, Sign company, Sign makers, “Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "vehicle-livery.php'"; $title = "Eagle Signs Wales - From Design to Installation, Vehicle Livery"; $description = "Quality Vehicle Livery in Wales"; $keywords = "Professional, Free Quote, van, lorry, vinyl printing, Installation, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "colour-printing.php"; $title = "Eagle Signs Wales - From Design to Installation, Full Colour Printing"; $description = "Full Colour Printing, from Design to Installation"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, Free Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "design.php"; $title = "Eagle Signs Wales – Design and Installation of Full Colour Signs and Banners"; $description = "Professional Sign and Banner Design and Installation West Wales"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, West Wales, Designs, Designer, Vehicle Printing, Print, Sign Makers, Fleet Livery"; break; case "contact.php"; $title = "Eagle Signs Wales - From Design to Installation, Carmarthen, Pembrokeshire"; $description = "Free Online Quote for Sign Printing in Wales"; $keywords = "Print, Sign Makers, Sign Company, Graphic Designs, Free Online Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; default: $title = "Default Title"; $description = "Default Description"; $keywords = "Default Keywords"; break; } ?>
Fixed, the correct symbol to use after case is : <?php switch (basename($_SERVER['SCRIPT_FILENAME'])) { case "index.php": $title = ""; $description = ""; $keywords = "index"; break; case "signs-banners.php": $title = "Eagle Signs Wales - From Design to Installation, Signs and Banners"; $description = "Professional Sign and Banner Design and Installation in Wales"; $keywords = "Commercial business, Vinyl, Graphics, Designs, Banners, Signs, Sign company, Sign makers, “Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "vehicle-livery.php": $title = "Eagle Signs Wales - From Design to Installation, Vehicle Livery"; $description = "Quality Vehicle Livery in Wales"; $keywords = "Professional, Free Quote, van, lorry, vinyl printing, Installation, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "colour-printing.php": $title = "Eagle Signs Wales - From Design to Installation, Full Colour Printing"; $description = "Full Colour Printing, from Design to Installation"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, Free Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; case "design.php": $title = "Eagle Signs Wales – Design and Installation of Full Colour Signs and Banners"; $description = "Professional Sign and Banner Design and Installation West Wales"; $keywords = "Full Colour Printing, Vinyl, Stationary, Graphic Design, Board Promotions, West Wales, Designs, Designer, Vehicle Printing, Print, Sign Makers, Fleet Livery"; break; case "contact.php": $title = "Eagle Signs Wales - From Design to Installation, Carmarthen, Pembrokeshire"; $description = "Free Online Quote for Sign Printing in Wales"; $keywords = "Print, Sign Makers, Sign Company, Graphic Designs, Free Online Quote, Carmarthenshire, Pembrokeshire, Llanelli, West Wales"; break; default: $title = "Default Title"; $description = "Default Description"; $keywords = "Default Keywords"; break; } ?> <title><?=$title?></title> <meta name="description" content="<?=$description?>" /> <meta name="keywords" content="<?=$keywords?>" /> PHP: