Schema.org< head> HTML标记:我可以只使用meta标签吗? [英] Schema.org <head> HTML markup: can I just use the meta tags?
问题描述
所以我当时正在查看Schema.org.我需要将我的<html>
标记更改为此吗?
So I was looking at Schema.org. Do I need to change my <html>
tag to this
<html itemscope itemtype="http://schema.org/Article">
或者我可以只在我的<head></head>
块中使用meta标签吗?
or can I just use only the meta tags within my <head></head>
block?
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<meta itemprop="image" content="http://www.example.com/image.jpg">
推荐答案
属性需要属于一个项目.使用itemscope
属性创建一个项目(itemtype
属性可以为该项目指定类型).
Properties need to belong to an item. You create an item with the itemscope
attribute (and the itemtype
attribute can give this item a type).
没有itemscope
,您的标记示例无效.
Without itemscope
, your markup example is invalid.
可以仅在head
元素内提供微数据,但不建议这样做有两个原因:
It is possible to provide Microdata only within the head
element, but it’s not recommended for two reasons:
-
微数据旨在用于您现有的标记.虽然在
head
中包含某些meta
/link
元素通常很有意义(与itemref
一起使用,例如),则大多数内容通常位于body
中.如果只想使用head
中的元素,则必须重复大部分内容.但是,如果您想走这条路,您可能更喜欢使用JSON-LD .
Microdata was intended to be used on your existing markup. While it can often make sense to include certain
meta
/link
elements in thehead
(withitemref
, see an example), most of the content is typically in thebody
. If you only want to use elements withinhead
, you would have to duplicate most your content. But if you want to go that route, you might prefer to use JSON-LD.
由于head
不允许使用分组元素(如div
),因此表达微数据变得很复杂.您将必须为每个属性使用itemref
,并为每个项目滥用style
这样的元素(请参阅此答案中的第一个代码段作为示例).
As head
doesn’t allow the use of a grouping element (like div
), it gets complex to express Microdata. You would have to use itemref
for every property and misuse an element like style
for every item (see the first snippet in this answer as example).
您的示例如下所示:
<head>
<style itemscope itemtype="http://schema.org/Article" itemref="p1a p1b p1c"></style>
<meta id="p1a" itemprop="name" content="The Name or Title Here">
<meta id="p1b" itemprop="description" content="This is the page description">
<link id="p1c" itemprop="image" href="http://www.example.com/image.jpg">
</head>
如果可以在head
元素上使用itemscope
,则更好:
If you can use itemscope
on the head
element, it would be better:
<head itemscope itemtype="http://schema.org/Article">
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<link itemprop="image" href="http://www.example.com/image.jpg">
</head>
但是,一旦您需要一个以上的项目(通常就是这种情况,例如Organization
/Person
就是author
等),这将不再起作用,您将需要像我的第一个片段中那样的解决方案.
But as soon as you need more than one item (which is typically the case, e.g., for the Organization
/Person
which is the author
etc.), this doesn’t work anymore, and you would need a solution like in my first snippet.
请注意,允许在body
元素内的微数据中使用meta
/link
元素.这使它变得更容易,因为您可以将div
元素用于itemscope
.因此,即使您复制内容而不是标记现有内容,也最好在body
:
Note that it’s allowed to use meta
/link
elements for Microdata within the body
element. This makes it way easier, as you can use div
elements for the itemscope
. So even if you duplicate your content instead of marking up your existing content, it would be preferable to do this in the body
:
<div itemscope itemtype="http://schema.org/Article">
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<link itemprop="image" href="http://www.example.com/image.jpg">
</div>
(我将image
属性的meta
元素替换为link
元素,因为使用meta
为此无效.)
(I replaced the meta
element for the image
property with a link
element, because using meta
is invalid for this purpose.)
这篇关于Schema.org< head> HTML标记:我可以只使用meta标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!