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. Link to comment https://forums.phpfreaks.com/topic/108839-solved-theory-question/ 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; ?> Link to comment https://forums.phpfreaks.com/topic/108839-solved-theory-question/#findComment-558283 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. Link to comment https://forums.phpfreaks.com/topic/108839-solved-theory-question/#findComment-558284 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! Link to comment https://forums.phpfreaks.com/topic/108839-solved-theory-question/#findComment-558290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.