jaymc Posted June 2, 2008 Share Posted June 2, 2008 Forget my reasons, im having a nightmare with php and dynamic pages in which I need to generat the html <title> tag I had a brain storm, if I put the <title><? echo $hurray; ?></title> before </body></html> I get what I want I have checked in IE and FIREFOX and they both read the title tag no problems at all However, the reason for all of this is for google, will google have any issues pulling out my title if its all the way down at the bottom of the page, more importantly, not in the head? I know its not best practice and probably un heard of, but the circumstances of time have led me to this Can I get away with it, rather dirty? Quote Link to comment Share on other sites More sharing options...
haku Posted June 2, 2008 Share Posted June 2, 2008 If it is showing up, then you can probably get away with it. However, it's recommended to have the title tag the very first thing in the head of your document, so you are definitely going against best practices here. I also don't know if your code will validate in this way. Why is it that you want to put it at the end of your script? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 3, 2008 Share Posted June 3, 2008 the title tag is ONLY allowed in the head section of your page. It defines the TITLE of your document that will show in the title bar of the window it is NOT for content markup purposes!!!!! Quote Link to comment Share on other sites More sharing options...
jaymc Posted June 3, 2008 Author Share Posted June 3, 2008 the title tag is ONLY allowed in the head section of your page. It defines the TITLE of your document that will show in the title bar of the window it is NOT for content markup purposes!!!!! But putting it after </body> and before </html> does display it in the title bar in both firefox and IE So, zero issues, apart from if google does not read it.. Quote Link to comment Share on other sites More sharing options...
haku Posted June 3, 2008 Share Posted June 3, 2008 I still don't get why you would want to do that. Quote Link to comment Share on other sites More sharing options...
jaymc Posted June 3, 2008 Author Share Posted June 3, 2008 Due to the setup of my php code, this is the only easy option without complete re structuring everything I've already wrote If its not going to cause a problem its better this way Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 3, 2008 Share Posted June 3, 2008 have you tried validating your markup jay? if your php is set up in such a way so as to prevent you from using markup properly then its not very useful or robust code... just using (x)html as intended is not difficult and should be done as a matter of course failure shows a distinct lack of professionalism on the developers part. Just because it doesn't cause a problem in the browsers you use does not mean it won't break in others... and if google doesn't see it your page ranking WILL suffer. Quote Link to comment Share on other sites More sharing options...
jaymc Posted June 3, 2008 Author Share Posted June 3, 2008 I have my code set out like this index.php : <html><head><title></title></head> <body> TABLES ETC HERE FOR BANNER <div><? echo include("webpages/page.php"); ?></div> </body> </html> The problem is, inside page.php is raw html and some mixed php. Because the html is not defined within the PHP when I use include it dumps the contents of page.php inside the div. To get the title coming frm page.php, i would need to include page.php before the head of the master index.php In doing this, the contents of page.php are outputed inside the <head> I tried using ob_start() to buffer the output, but in doing that, I was unable to retrieve the $pageTitle variable which was set inside of page.php Just to note, there are about 200 page.php type files, so not so feasable to go in and change it all, especially the way i have mixed raw html and php within those files, rather than all html inside php variables Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted June 4, 2008 Share Posted June 4, 2008 I have my code set out like this index.php : <html><head><title></title></head> <body> TABLES ETC HERE FOR BANNER <div><? echo include("webpages/page.php"); ?></div> </body> </html> The problem is, inside page.php is raw html and some mixed php. Because the html is not defined within the PHP when I use include it dumps the contents of page.php inside the div. To get the title coming frm page.php, i would need to include page.php before the head of the master index.php In doing this, the contents of page.php are outputed inside the <head> I tried using ob_start() to buffer the output, but in doing that, I was unable to retrieve the $pageTitle variable which was set inside of page.php Just to note, there are about 200 page.php type files, so not so feasable to go in and change it all, especially the way i have mixed raw html and php within those files, rather than all html inside php variables All I have to say is that you designed the website extremely poorly. This "band-aid" solution is good for so long. .. until Yahoo! and google release their bots that look after semantics! ; Quote Link to comment Share on other sites More sharing options...
jaymc Posted June 4, 2008 Author Share Posted June 4, 2008 Ok, I guess I will go re code Quote Link to comment Share on other sites More sharing options...
haku Posted June 5, 2008 Share Posted June 5, 2008 I generally set up a function with a switch statement in it that outputs the title of the page. For example: function page_title($page_name) { switch($page_name) case $page_name = "index.php"; echo "my_site.com: Index"; break; case $page_name = "about_us.php"; echo "my_site.com: About Us"; break; } Then I call the function inside my title tags: <title><?php page_title(get_page_name()); ?></title> note: I also have a function, called get_page_name, that gets the current page name as you can see in the example there. 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.