adamlacombe Posted July 10, 2009 Share Posted July 10, 2009 I have a question, what do you think is a good way to get the title tags to say the name of the page? I had it so: echo '<title>'.$ssitename.' - '.$title.'</title>'; was on the bottom of the index page so all I would put was: case 'feedback': include ('pages/feedback.php'); $title="feedback"; break; but I figured out the title tags need to be in the head tags for google searches. What would be the best way to do that because I have a template system so I cant have the title tags in each file, they need to stay in the header file but needs to read the page name. Link to comment https://forums.phpfreaks.com/topic/165499-title-in-head-tags/ Share on other sites More sharing options...
The Eagle Posted July 10, 2009 Share Posted July 10, 2009 If you have a configuration file, enter this text into it, if you do not, please create it and call it something such as config.php. // Title of site $sitename = "Site name"; After you've done this, you're going to need to add an include to the beginning of each of your PHP pages. Code below. include('filename/config.php'); It's also easy to do it in HTML, such as. ?> <html> <head> <title><?=$sitename?> - Text if wanted</title> Link to comment https://forums.phpfreaks.com/topic/165499-title-in-head-tags/#findComment-872883 Share on other sites More sharing options...
MatthewJ Posted July 10, 2009 Share Posted July 10, 2009 If you have a configuration file, enter this text into it, if you do not, please create it and call it something such as config.php. // Title of site $sitename = "Site name"; After you've done this, you're going to need to add an include to the beginning of each of your PHP pages. Code below. include('filename/config.php'); It's also easy to do it in HTML, such as. ?> <html> <head> <title><?=$sitename?> - Text if wanted</title> You shouldn't use short tags... often times they are turned off. Link to comment https://forums.phpfreaks.com/topic/165499-title-in-head-tags/#findComment-872891 Share on other sites More sharing options...
adamlacombe Posted July 10, 2009 Author Share Posted July 10, 2009 I already have the $sitename thing done, its coming from a mysql query but its hard to explain what im saying.. here take a look at my index file and it will be a liitle easier to understand what im saying... <? include "includes/db.php"; session_start(); include "includes/config.php"; $username = $_SESSION['username']; if($sstatus == online || $_SESSION['type'] == 1){ if($sstatus == offline){ echo'<center>Please Remember '.$ssitename.' Is In Offline Mode!</center><br />'; } include "themes/$theme/top.php"; include "themes/$theme/right.php"; include "themes/$theme/left.php"; switch($_GET['action']){ case 'tos': include ('pages/tos.php'); break; case 'login': include ('pages/login.php'); break; case 'logout': include ('pages/logout.php'); break; case 'register': include ('pages/register.php'); break; case 'profile': include ('pages/profile.php'); break; case 'profilecp': include ('pages/profilecp.php'); break; case 'addfav': include ('pages/addfav.php'); break; case 'favorites': include ('pages/favorites.php'); break; case 'messages': include ('pages/messages.php'); break; case 'members': include ('pages/members.php'); break; case 'search1': include ('pages/search.php'); break; case 'search': include ('pages/search.html'); break; case 'browseg': include ('pages/game/browse.php'); break; case 'game': include ('pages/game/game.php'); break; case 'commentg': include ('pages/game/comment.php'); break; case 'browsev': include ('pages/video/browse.php'); break; case 'video': include ('pages/video/video.php'); break; case 'browsej': include ('pages/joke/browse.php'); break; case 'joke': include ('pages/joke/joke.php'); break; case 'feedback': include ('pages/feedback.php'); break; default: include ('pages/main.php'); break; } include "themes/$theme/bottom.php"; }else{ include "themes/$theme/offline.php"; } ?> I want it so each page has a title in title tags but I want the title tags in the head tags but the head tags are in "top.php" any idea how to get each page a title? Link to comment https://forums.phpfreaks.com/topic/165499-title-in-head-tags/#findComment-872963 Share on other sites More sharing options...
adamlacombe Posted July 11, 2009 Author Share Posted July 11, 2009 Ok I finally figured it out! But have one last question. I have this: if($_GET['action'] == feedback){ $title="feedback"; } How would I put that in an array? I thought this might work but it doesn't: $t= array(tos, feedback); if($_GET['action'] == $t){ $title= array("tos", "feedback"); } Link to comment https://forums.phpfreaks.com/topic/165499-title-in-head-tags/#findComment-873257 Share on other sites More sharing options...
xtopolis Posted July 11, 2009 Share Posted July 11, 2009 Are you saying so that it only changes it to valid titles? <?php $validTitles = array("tos", "feedback", "home"); if(in_array($_GET['action'], $validTitles)) { $title = $_GET['action']; }else{ $title = "yoursitename.com"; } Link to comment https://forums.phpfreaks.com/topic/165499-title-in-head-tags/#findComment-873335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.