bruckerrlb Posted June 5, 2008 Share Posted June 5, 2008 I am about to do something I've never even thought about, and I'm trying to think how I can do this, but have no idea. I created my website in php, and am using the include("header.php"); for all of my pages, and this ultimately goes to my header file, and this is great, because I can keep my stylesheets and what not in there. The problem lies in the title tag, right now all of my pages (about 11) have the same title, and I need to change this to optimize the site for the search engines. Does anyone know how I can have my include statement and yet custom title tags? Is this even possible? I am pretty sure it is, just don't know how. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 in each file: <?php $title = "the title of this page"; include("header.php); In your header.php file: <html> <title><?php print $title; ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 5, 2008 Share Posted June 5, 2008 Yeah, just define, say, $title before you include the header file. Then echo out that, or ,if it's not been set, a default title. So, something like this: Any page: <?php $title = 'Custom title for this page'; include('header.php'); ?> header.php <?php if(!isset($title)){ $title = 'Default title'; } //echo out title and other header information ?> Remember, an include is like just taking the contents of your included page and running it as if that code were in the page already. Quote Link to comment Share on other sites More sharing options...
bruckerrlb Posted June 5, 2008 Author Share Posted June 5, 2008 That worked perfectly, thanks I appreciate it! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.