The right way to set microdata for Q & A HTML

Let's say you have a simple HTML question and answer and would like to add microdata, how can this be done?

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

I know an example of schema.org , but I don't find it very clear. This seems like an overkill. I need a simple solution. Can I continue 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 say what the question is and what the answer is. Is this enough for search engines? Or I need something more complex, for example:

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

Uses itemprop="name" correct way to tell, what is the question? What is the difference between itemprop="name" and itemprop="text" in the above schema.org example?

+5
source share
1 answer

In the first example, Microdata analyzers only recognize that there is a Question and Answer element without any additional content. Microdata does not indicate that you need to consider the contents of HTML elements with itemscope attributes; it only cares about property values .

Testing your example with Microdata Online Analyzers :


name vs. text

For this very question, name will be "The correct way to set microdata for Q & A HTML", and text will be the body of the question ("Let's say one has a simple question ...").

If the whole question consists only of such a single short string, Id uses the text property instead of name (*). name can basically also be something like "Question 1" if you want / need it.

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

* The example for Answer also uses text (and does not have a name ).


You can also use the suggestedAnswer property questions and / or the parentItem property answers to link the two elements.

So for a short question, it might look like this:

 <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> 
+6
source

Source: https://habr.com/ru/post/1207981/


All Articles