Why has the <title>-tag to be placed into the <head> element?

泄露秘密 提交于 2021-02-05 09:54:50

问题


In the specific example, I got a website that is including many different content pages. Depending on the currently included page, the title is a different one. To achieve this, I got the following dynamic <title> almost at the end of the document.

<title><?php echo $title1,' - ',$title2 ?> - *and some static text here*</title>

$title2 is always in the directly included file and $title1 is even deeper.

So far I didn't notice any kind of disadvantages. All titles are shown properly and all search results on several search engines seem to accept this method and display it correctly.

Several sites like W3 say that the <title> must be in the <head> though ... but there's no reason given.

So, what kind of disadvantages do I have due to this?

  • Do search engines rank the site badly for that?
  • Will old browser versions simply not display the title at all?
  • Or is this information just old and it doesn't make a difference these days?

回答1:


Do search engines rank the site badly for that? and "Will old browser versions simply not display the title at all?"

Maybe, or new ones will. The thing, is, you can never no. You do something that is not standard, so for all you know, Google might decide to not index your title at all starting tomorrow, and 'suddenly' nobody can find your site anymore.

Or is this information just old and it doesn't make a difference these days?

Yes and no. The information you linked to is about the HTML 4.01 standard, which is indeed old, but that information is still valid for HTML5.

You don't have to have a HEAD tag by the way. The shortest valid HTML5 document with a title would be:

<!DOCTYPE html>
<title>Title</title>

But still, a TITLE after a BODY is still not valid. Even though you can omit the HEAD tag, it is implied when you start a TITLE tag. And the HEAD tag has to be the first tag inside the HTML tag. A title at the end implies a head at the end, which makes your document invalid.

See: W3: The head element (html5)

And when in doubt, you can also check the W3 validator. It will tell you that that minimal document I posted above is valid, but it will be invalid as soon as you start a BODY tag above the title, regardless if and where you end it.



来源:https://stackoverflow.com/questions/37027157/why-has-the-title-tag-to-be-placed-into-the-head-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!