How can I nest <meta> tags for Microdata?
Asked Answered
D

2

6

I've this kind of structure:

+ EVENT -> itemtype="http://schema.org/Event
 + Name   
 + Date   
 + ...
 + LOCATION -> itemtype="http://schema.org/Place
        *          Name
     + Url
     + ...

I won't show all the Place information on the website, but I want to use the information for Microdata. And so I want to add this tag:

<meta itemprop="location" itemscope itemtype="http://schema.org/Place">

Works fine.

But how can I add the itemprops for name, url, "address" for location?

It won't works like :

<meta itemprop="location" itemscope itemtype="http://schema.org/Place">
<meta itemprop="url" content="https://example-location.com">
<meta itemprop="name" content="exampleLocationName">
Donelson answered 2/2, 2017 at 15:56 Comment(2)
Welcome to stackoverflow! Please take a moment to review our tour.Distress
A possible duplicate of #37723846.Jacklighter
C
4

Probably like this. Actually unsure of it.

<meta itemprop="location" content="" itemscope itemtype="http://schema.org/Place" itemref="place-url place-name">
<link id="place-url" itemprop="url" href="https://example-location.com">
<meta id="place-name" itemprop="name" content="exampleLocationName">

Can’t you just ditch the ugly empty content?

https://www.w3.org/TR/microdata#x7-2-content-models

If a meta element has an itemprop attribute, the name, http-equiv, and charset attributes must be omitted, and the content attribute must be present.

You can’t.

Why <link> instead of <meta>?

Because only URL property elements can have an absolute URL as their values, and <link> is one while <meta> is not.

From https://www.w3.org/TR/microdata#x5-4-values-the-content-attribute-element-specific-attributes-and-element-content:

The algorithm to determine the value for a name-value pair is given by applying the first matching case in the following list:

  • If the element also has an itemscope attribute: the value is the item created by the element.
  • If the element has a content attribute: the value is the textContent of the element’s content attribute.

 

The URL property elements are the a, area, audio, embed, iframe, img, link, object, source, track, and video elements.

 

If a property’s value, as defined by the property’s definition, is an absolute URL, the property must be specified using a URL property element.

How about nesting <meta> tags?

You cannot, as the <meta> is a void element, which must not have any children.


Better yet

Have you considered using JSON-LD instead?

Circumvent answered 6/11, 2019 at 5:51 Comment(0)
B
0

You have to wrap the event microdata inside the Event entity. In your specific case:

<div itemscope itemtype="http://schema.org/Event">
    <h1 itemprop="name">Name</h1>
    <time itemprop="startDate" datetime="2018-07-28T20:23:16+02:00" content="2018-07-28T20:23:16+02:00">28 luglio 2018</time>
    ...
    <div itemprop="location" itemscope itemtype="https://schema.org/Place">
        <h2>Location: <span itemprop="name">Location Name</span></h2>
        <meta itemprop="url" content="https://example-location.com">
    </div>
</div>

If you want to hide all the location informations, you can act as above but hide the whole Event entity:

<div itemscope itemtype="http://schema.org/Event">
    ...
    <div style='display: none;' itemprop="location" itemscope itemtype="https://schema.org/Place">
        <meta itemprop="name" content="Location Name">
        <meta itemprop="url" content="https://example-location.com">
    </div>
</div>
Barnette answered 30/8, 2018 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.