为什么要在< head>标签中放置< title>标签?元素? [英] Why has the <title>-tag to be placed into the <head> element?

查看:61
本文介绍了为什么要在< head>标签中放置< title>标签?元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在特定示例中,我得到了一个包含许多不同内容页面的网站.根据当前包含的页面,标题可能有所不同.为此,我几乎在文档末尾获得了以下动态< title> .

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 始终位于直接包含的文件中,而 $ title1 甚至更深.

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

W3 之类的几个网站都说< title> 必须< head> 中,但是...没有给出原因.

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?

  • 搜索引擎是否为此对网站排名很差?
  • 旧版本的浏览器根本不会显示标题吗?
  • 还是这些信息只是陈旧的,这些天没有什么作用?

推荐答案

搜索引擎是否为此对该网站进行了严重排名?"旧版本的浏览器根本不会显示标题吗??"

也许,或者会有新的.关键是,你永远不会没有.您所做的事情不是标准的,因此,就您所知,Google可能决定从明天开始完全不对标题建立索引,并且突然"没有人能再找到您的网站.

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.

还是这些信息只是陈旧的,这些天没有什么作用?

是,不是.您链接到的信息是关于HTML 4.01标准的,该标准确实很旧,但是该信息对于HTML5仍然有效.

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.

顺便说一句,您不必具有HEAD标签.带有标题的最短有效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>

但是,BODY之后的TITLE仍然无效.即使您可以省略HEAD标记,但在启动TITLE标记时隐含该标记.并且HEAD标记必须是HTML标记内的第一个标记.末尾的标题意味着末尾的标题,这会使您的文档无效.

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.

请参阅: W3:head元素(html5)

如果有疑问,您还可以检查 W3验证器.它会告诉您我上面发布的最小文档是有效的,但是,无论您在何处结束,只要在标题上方启动一个BODY标签,该文档就将无效.

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.

这篇关于为什么要在&lt; head&gt;标签中放置&lt; title&gt;标签?元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆