[英]How to define the Microdata markup for an image when it's actually a picture tag?
在http://schema.org/Product范圍內,我想定義圖像的標記。 通常它看起來如下:
<img itemprop="image" src="/path-to-image.suffix" alt="image-description" />
但是,現代響應式頁面使用<picture>
標簽。 我試過...
<picture itemprop="image">
<source media="(max-width: ${viewport-size-1})" srcset="/path-to-image-size-1.suffix">
<source media="(min-width: ${viewport-size-2})" srcset="/path-to-image-size-2.suffix">
<img src="/fallback-path-to-image.suffix" alt="image-description">
</picture>
但它似乎不被谷歌的結構化數據測試工具所接受。 將它添加到<picture>
中的<img>
標簽對我來說似乎不正確,因為它沒有突出整個上下文,因此忽略了圖像以各種分辨率存在的事實......
picture
標簽的正確微數據圖像標記是什么?
您必須在img
元素上指定itemprop
屬性,而不是在picture
元素上:
<picture>
<source media="(max-width: ${viewport-size-1})" srcset="/path-to-image-size-1.suffix">
<source media="(min-width: ${viewport-size-2})" srcset="/path-to-image-size-2.suffix">
<img itemprop="image" src="/fallback-path-to-image.suffix" alt="image-description">
</picture>
原因是因為如果 Microdata 屬性應具有 URL 作為值,則只能使用某些元素,即所有具有href
或src
屬性的元素。
ImageObject
值您必須在img
元素上指定contentUrl
屬性:
<picture itemprop="image" itemscope itemtype="http://schema.org/ImageObject">
<source media="(max-width: ${viewport-size-1})" srcset="/path-to-image-size-1.suffix">
<source media="(min-width: ${viewport-size-2})" srcset="/path-to-image-size-2.suffix">
<img itemprop="contentUrl" src="/fallback-path-to-image.suffix" alt="image-description">
</picture>
也允許在source
元素(而不是img
元素)上指定itemprop
,但它需要具有src
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.