Jump to content

[SOLVED] TITLE Tag blooper


jaymc

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

:)

Link to comment
Share on other sites

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!  ; ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.