Question

I just started using schema.org meta tags to highlight structured data on my website.

I am using node.js, express, and jade to generate my content. I am setting up these tags on some but not all pages. I don't want to misrepresent the non-tagged pages to search engines.

I haven't found an elegant way to only insert the itemscope attribute into my html document situationally.

edit - @martinhepp suggests passing the attribute string to Jade and inserting it inside the tag. I'd like to do this but I don't know how. Here is my attempt and the output.

//node.js
locals.testSchemaTag = 'itemscope itemtype="http://schema.org/Product"';
//jade
p(locals.testSchemaTag) Foo Bar
//rendered HTML
<p locals.testschematag="">Foo Bar</p>

So that would be preferable. But if that doesn't work or no one knows how to do it, for pages where I don't want to designate a particular schema, is it sufficient to set itemscope to false?

Here's what I'm doing now.

// node.js
res.locals.schema = res.locals.schema || { 
  itemtype: "false", 
  itemscope: "false", 
  properties: [], 
};         
if(res.locals.schema.itemtype !== "false"){
  res.locals.schema.itemscope = "itemscope";
  res.locals.schema.properties = res.locals.schema.properties || []; 
};   

// jade
!!!
html(itemscope=locals.schema.itemscope, itemtype=locals.schema.itemtype)
  head

// rendered output A
<html itemscope="itemscope" itemtype="http://schema.org/Restaurant">

// rendered output B
<html itemscope="false" itemtype="false">

Will this confuse search engines or will they recognize that I am disabling the itemscope and itemtype attributes of my <html> element here?

Was it helpful?

Solution

I work for Yandex (yandex.ru/.com - Russian most popular Search Engine) and can tell how do we deal with it. I bet though that process is pretty the same for every SE.

So three things here that should be taken into account.

1.Microdata W3C doc says

An element with the itemscope attribute specified creates a new item, a group of name-value pairs.

That is if you put itemscope attribute in HTML element, it is treated as an item. Even in your case (in fact "=false" is ignored). If you don't want to define new item you simply shouldn't use itemscope attribute at all.

2.Every Search Engine which uses markup has it's own validator tool - instrument, where you can check markup processing specifically for this SE. For Yandex it is here, for Google is here. Bing has one too but it requires Signing In in their webmaster tools first. Use it for every question that you have about markup processing for partucular SE and you will get pretty detailed answer.

So you didn't provide example of markup but let's consider this simple one.

<div itemscope="false" itemtype="false">
  <span itemprop="name">Not a happy camper</span> -
  by <span itemprop="author">Ellie</span>,
  <meta itemprop="datePublished" content="2011-04-01">April 1, 2011
  <span itemprop="description">The lamp burned out and now I have to replace it. </span>
</div>

So Yandex's validator says the following:

microdata
  WARNING: itemtype false not recognized by validator
  itemType = false
    name = Not a happy camper
    author = Ellie
    datepublished = 2011-04-01
    description = The lamp burned out and now I have to replace it.

As you see, itemscope="false" was ignored and type of the item was set to "false" (due to itemtype="false"). That is Yandex found some entity but doesn't know, what to do with it (more about this in the third point).

What about Google?

Item 
  property: 
  name: Not a happy camper
  author:   Ellie
  datepublished:    2011-04-01
  description:  The lamp burned out and now I have to replace it.

Almost the same except that it treated entity as without type at all.

3.But in fact you shouldn't really care about this much :) Not any Search Engine works with full vocabulary and all its types (schema.org, microformats or any other). That is every Search Engine has list of types it understands and has products for. For Yandex list is here, for Google is here, for Bing is here. As you can see support is pretty limited but is actively evolving. What does this actually mean? That even though your "false" markup is treated as an object it isn't used anywhere in fact. So you can do it safely :)

OTHER TIPS

First of all: I assume that all you are talking of happens on the server side. Any client-side Javascript will not be available for mainstream search engine crawlers, only to future schema.org-aware browser extensions.

Now, the simple answer is: If you want to suppress markup in certain cases, simply put a conditional clause around both the itemscope and the itemtype keywords.

// rendered output A
<html itemscope="itemscope" itemtype="http://schema.org/Restaurant">

// rendered output B
<html>

That's it.

Also note that in most cases, the html element is the wrong place for a schema.org type. For schema:WebPage, use the head element. For schema:Product, schema:Offer etc., use the respective element in the body of the template, e.h. h1, div, article, section, ...

Martin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top