Specifying complex structure with meta tag in Microdata

醉酒当歌 提交于 2020-01-12 09:53:35

问题


How can I tag information that is not displayed on the page with the Microdata format?

Typically, we do not want to display publisher/author info on the page, but Google requires this info for Articles, and they have a complex structure.

I do not want to put this data in hidden span/div or anything, so I thought I'd use the meta tag. But how do I specify the logo and name of the publisher entity using metas? Do I need to use itemref somehow?

<section itemscope itemtype="http://schema.org/Article">
 <meta itemprop="keywords" content="kw1, kw2" />
 <meta itemprop="publisher" content="© My Company" /><!-- ??-->

I've already looked at Using a different image for microdata that isn't displayed in the article?, but is it possible to achieve what I want without using JSON-LD? If no, can I use both JSON-LD and meta/tag descriptions?


回答1:


I think you have two (in some cases three) options using Microdata.

meta/link + div

The most simple solution is to use meta/link elements for properties with non-item values, and div elements for properties with item values.

<section itemscope itemtype="http://schema.org/Article">
  <meta itemprop="keywords" content="kw1, kw2" />
  <div itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="My Company" />
  </div>
</section>

meta/link elements are hidden by default, and div elements that contain nothing else than meta/link elements don’t show anything either.

meta/link + itemref

If you don’t want to use div elements, it’s possible to use meta elements for representing an item. But then you have to

  • provide an empty content attribute (ugly), and
  • use the itemref attribute for every property you want to add to this item.
<meta itemscope itemprop="publisher" content="" itemtype="https://schema.org/Organization" id="pub" itemref="pub-name" />

<meta itemprop="name" content="My Company" id="pub-name" />

<section itemscope itemtype="http://schema.org/Article" itemref="pub">
  <meta itemprop="keywords" content="kw1, kw2" />
</section>

Note that this does not work for top-level items, because the meta element requires an itemprop attribute (which can’t be empty).

(meta/link +) itemid

In some cases it might be possible to reference URIs for the items (instead of embedding them), e.g., if you have another page that contains the data about the publisher.

However, note that it’s not clear if Google supports this.

<section itemscope itemtype="http://schema.org/Article">
  <meta itemprop="keywords" content="kw1, kw2" />
  <link itemprop="publisher" href="/publisher#this" />
</section>
<!-- on the page /publisher -->

<section itemscope itemtype="http://schema.org/Organization" itemid="#this">
  <h1 itemprop="name">My Company</h1>
</section>


来源:https://stackoverflow.com/questions/37723346/specifying-complex-structure-with-meta-tag-in-microdata

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