Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right way to set microdata for Q&A HTML

Say one has a simple question and answer HTML and would like to add microdata, how should one proceed?

<h2>My Question</h2>
<p>My Answer</p>

I am aware of the schema.org example, but I don't find it very clear. It looks like overkill. I need a simple solution. Can I proceed this way?

<h2 itemscope itemtype="http://schema.org/Question">My Question</h2>
<p itemscope itemtype="http://schema.org/Answer">My Answer</p>

I just want to tell what the question is and what the answer is. Is this enough for search engines? Or should I have something more sophisticated like:

<div itemscope itemtype="http://schema.org/Question">
  <h2 itemprop="name">My Question</h2>
  <p itemscope itemtype="http://schema.org/Answer">My Answer</p>
</div>

Is using itemprop="name" the right way to tell what the question is? What is the difference between itemprop="name" and itemprop="text" in the schema.org example mentioned above?

like image 999
Jérôme Verstrynge Avatar asked Nov 30 '14 13:11

Jérôme Verstrynge


People also ask

What is the example of microdata?

For example, Yandex, a major search engine in Russia, supports microformats such as hCard (company contact information), hRecipe (food recipe), hReview (market reviews) and hProduct (product data) and provides its own format for the definition of the terms and encyclopedic articles.

What is microdata markup?

Microdata is a specification to embed machine-readable data in HTML documents. Microdata consists of name-value pairs (known as items ) defined according to a vocabulary. A collection of commonly used markup vocabularies are provided by schema.org.

Does microdata help SEO?

There are many SEO related benefits related to using Schema Markup code or “microdata.” It helps to play an important role for websites and eCommerce businesses that leverage the opportunity of using Microdata markup code to stand out in search results, increase page rank, and (CTR) improve click-through rate.

Should I use microdata or JSON-LD?

With JSON-LD, a JavaScript object is inserted into the HTML of your page to define data, whereas microdata uses HTML tags and attributes to define data. In its structured data guidelines, Google states that it recommends JSON-LD over microdata for web content.


1 Answers

From your first example, Microdata parsers will only learn that there is a Question and an Answer item, without any further content. Microdata doesn’t specify that the content of HTML elements with itemscope attributes has to be considered, it only cares about property values.

Testing your example with some online Microdata parsers:

  • W3C’s Microdata to RDF Distiller extracts this RDF (in Turtle):

    <> md:item ( [ a schema:Question ] [ a schema:Answer ] );
        rdfa:usesVocabulary schema: .
    
  • The Structured Data Linter has almost the same output.

  • Yandex’s Structured data validator has similar output.

  • Google’s Structured Data Testing Tool doesn’t extract anything.


name vs. text

For this very question, the name would be "Right way to set microdata for Q&A HTML" and the text would be the question body ("Say one has a simple question …").

If the whole question consists only of such a single, short line, I’d use the text property instead of name (*). name could, principally, also be something like "Question 1", if you want/need it.

But you could also use both properties for a short question, i.e., itemprop="name text", but this is maybe not very elegant (but it can make sense especially if you know that some data consumer makes use of the name property).

* The example for Answer also uses text (and has no name).


You might also want to use Question’s suggestedAnswer property and/or Answer’s parentItem property to relate these two items.

So for a short question it could look like:

<section itemscope itemtype="http://schema.org/Question">
  <h2 itemprop="name text">My Question</h2>
  <div itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
    <p itemprop="text">My Answer</p>
  </div>
</section>
like image 199
unor Avatar answered Sep 20 '22 12:09

unor