Rich snippet support is now available in the 7.x-2.x-microdata branch. Please help testing.

Both Microdata and RDFa are supported, as in
https://support.google.com/webmasters/answer/185417

The alternative schema.org style has been discarded because it is not supported by search engines (yet).

Original request by Jawi

How can I easily ad mircodata to the breadcrumbs so google wil pick up rich snippets?

I've read some adjustments in the theme template file, but I would like to generate this rich snippet breadcrumb with the crumbs module.

Thanks for the support and the great module that crumbs is now :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

donquixote’s picture

Funny that you are the first to request this! I thought I had an older issue about this in the queue. But cannot find any.

I think really the only way to do this with the current version is using the theme layer. Either with a preprocess, or with a theme function.

There are the usual theme('breadcrumb', ..) theme hooks from core, and then you can look at crumbs_theme() for additional theme hooks defined in crumbs. The ones that matter are theme_crumbs_breadcrumb_link() and theme_crumbs_breadcrumb_current_page().

Here is the code that generates the breadcrumb html

So what you can do is use hook_preprocess_crumbs_breadcrumb_link(&$vars) to modify the $vars['item']['localized_options']['attributes']. Or you override the theme function.

I am interested in your solution.

donquixote’s picture

Cool, look at this: http://www.schema.org/WebPage

<div itemprop="breadcrumb">
  <a href="category/books.html">Books</a> >
  <a href="category/books-literature.html">Literature & Fiction</a> >
  <a href="category/books-classics">Classics</a>
</div>

Looks far cleaner than this junk: https://coderwall.com/p/p0nvjw

<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
  <a href="http://www.example.com/" itemprop="url">
    <span itemprop="title">Example.com</span>
  </a>
</li>

See http://stackoverflow.com/a/7044467/246724

donquixote’s picture

Maybe the body itemprop should be done by another module, so it can use whatever schema that the rest of the site uses?

donquixote’s picture

donquixote’s picture

@Jawi:
I created and pushed a new branch 7.x-2.x-microdata.
Can you try it?

Improvements:
- Enabling theme_breadcrumb override for specific themes is now more reliable.
- Rich snippet support for those themes that are overriden. Option for either microdata or RDFa, as in https://support.google.com/webmasters/answer/185417
- Configuration in admin/structure/crumbs/display.
- Theme hook THEME_crumbs_breadcrumb_current_page() merged into THEME_crumbs_breadcrumb_link().
- New theme hooks THEME_crumbs_breadcrumb_link__microdata() and THEME_crumbs_breadcrumb_link__rdfa()
- New variables sent to theme functions. Usage of <nolink> in href for last item, if it is to be rendered in span tag.

donquixote’s picture

Title: microdata » Rich snippets / Microdata / RDFa
Issue summary: View changes
Jawi’s picture

Tested microdata support for crumbs module as in #5.

Their is a nice optionbox added to the display settings.
crumbs display settings

On my user-case I get this error - and the theme breadcrumb is not overwritten.
Warning: debug_backtrace() expects at most 1 parameter, 2 given in

crumbs_theme_registry_alter() (line 217 of /~/public_html/sites/all/modules/crumbs/crumbs.module).

For so far looking good - almost working as it should!

Jawi’s picture

donquixote’s picture

Warning: debug_backtrace() expects at most 1 parameter, 2 given

This must be a PHP version thing..

How good are you with development, or theming?
This patch involves some technical changes that go beyond just microdata/RDFa and that I would love some feedback on.

1. I fixed the "Override theme implementations".
So far this was behaving strangely, because theme registry rebuild does not work as it is supposed to, if it is called on something other than the currently active theme.
So now you see this '?' for themes that are not yet rebuilt.

2. Changed theme hooks.
Before we had THEME_crumbs_breadcrumb_link() and THEME_breadcrumb_current_page() and THEME_breadcrumb(). Now we have THEME_crumbs_breadcrumb_link() and THEME_crumbs_breadcrumb_link_microdata() and THEME_crumbs_breadcrumb_link_rdfa(), and of course we still have THEME_breadcrumb(). And in case of RDFa, some of the magic happens in theme_breadcrumb() (with the $attributes array).
All the Microdata and RDFa magic only happens on themes where the override option is active.
Do you think this is a good solution for themers?

donquixote’s picture

Can you try this in crumbs.module where the warning is coming from?

  // Figure out which theme this applies to.
  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
    $trace = debug_backtrace(0, 3);
  }
  else {
    // Second parameter not supported in PHP < 5.4.0. It would cause a
    // "Warning: debug_backtrace() expects at most 1 parameter, 2 given".
    $trace = debug_backtrace(0);
  }
Jawi’s picture

I've tested the module and send u a report by e-mail. The microdata doesn't apear for now. Can't figure out why it's not apearing.

Cheers,

JW

donquixote’s picture

Hi,
i can't find the email in my inbox.. can you send again?

GaëlG’s picture

I just tested the branch. I had the same PHP version problem, solved by #10. But there's also another one: in CurrentPageInfo->breadcrumbHtml(), this check fails:

if (!empty($page->richSnippetMode)) {

whereas this one works:

$rsm = $page->richSnippetMode;
if (!empty($rsm)) {

This is probably due to PHP version too. With these 2 edits, my breadcrumb is correctly detected by Google here: http://www.google.com/webmasters/tools/richsnippets

Thank you for the work, I hope this nice feature will be included soon.

donquixote’s picture

Re #13:
This is now fixed in https://github.com/donquixote/drupal-crumbs/compare/7.x-2.x-microdata?ex...

What is still holding me up is the theme system changes.
https://github.com/donquixote/drupal-crumbs/commit/85bb8ae5feb305364daec...
I don't want to throw random API changes at my users - at least there should be some discussion about it.

See also #2167233: Rethink Crumbs theme API: Breadcrumb formatters?

jrabeemer’s picture

I'm looking forward to this getting into the core module.

Jawi’s picture

@donquixote --> The microdata function added to the crumbs module is working fine in our drupal commerce kickstart install. tested and no issues found. Does what it should and snippets are visible for http://www.google.nl/webmasters/tools/richsnippets

donquixote’s picture

Hi Jawi,
thanks for testing!
The challenge still is whether the changes to the theme layer are future-proof.

The last months were quite busy, but I am going to have some more time the next weeks so I can have a closer look.
(and btw I am also working on some nice improvements to the plugin management form)

GaëlG’s picture

Any news on this?

donquixote’s picture

Hi!
Still same issues as in #17. I don't want to create facts that I later can't reverse, with regard to the theme layer.
I would like to go straight to the new "breadcrumb formatter" idea.
But for that I would like to use PSR-4 and a D8-style plugin system. And PSR-4 (namespaces) would break the PHP 5.2 compatibility and bring a bunch of changes, which is not going to happen in the 7.x-2.x branch.

The recent changes after 7.x-2.0-beta13 seem to have been quite disruptive too, so I would like to stabilize and finally release a 7.x-2.0 stable.

BUT, I have a different plan now :)
I am already working on a "D8 plugins for D7" solution locally. Currently my motivation is that I no longer want to write procedural field formatters.
And once that is out I will create a new module "breadcrumbformat" which will use this to create a breadcrumb formatter plugin type, with Crumbs as a soft dependency. There will be formatters for rich snippets, and possibly other things.

donquixote’s picture

A quick heads-up:
I have started with the "D8 plugins for D7" module:
https://github.com/donquixote/d8plugin
A lot of this will still change, only treat it as a preview.

szy’s picture

I can't find the Microdata options (D7) mentioned on the screenshot above. Are they unavailable now?

Thanks for your nice module.

Szy.

donquixote’s picture

@szy (#21):
You get this feature if you use the git branch 7.x-2.x-microdata as mentioned in #5. Probably a good idea to merge it with the current 7.x-2.x, or else you will miss out on the latest features and bug fixes.

This has not been merged into 7.x-2.x yet, because it changes the theme API of this module in a way I am not 100% happy with yet. All of this would need to be supported in future versions. It is a bit stuck, also because I had other things to do.

Another solution, maybe the preferable one, is to implement this in your theme.
The theme hooks to work with are:
- theme_breadcrumb() (core)
- theme_crumbs_breadcrumb_link()
- theme_crumbs_breadcrumb_current_page()

szy’s picture

Thanks for the explanation :)

Unfortunately, it looks like Microdata branch does not display Microdata crumbs. At least for me.

Szy.

Dom.’s picture

For me neither: no microdata displayed using the option.

zenimagine’s picture

Hello, how to view the microdata? Do you have a patch? I tested both versions of the module, but none showed the microdata

donquixote’s picture

Status: Active » Needs review
FileSize
4.04 KB

I present something better than microdata or RDFa:
JSON-LD!

The advantage:
JSON-LD can stay in the header (or any place) and does not conflict with themes.
This means you can have your regular HTML breadcrumb in the page html, and then a JSON-LD version in the header.
http://schema.org/BreadcrumbList
https://webmasters.stackexchange.com/questions/115107/seo-schema-org-bre...

The patch does not apply the "show first item" and "show last item" and "shortest visible breadcrumb" settings to breadcrumbs in search engine results. This is on purpose.

I am going to test-drive this on some sites that I maintain, before I merge it.

donquixote’s picture

For now this is not controlled by a setting.
Perhaps it should be?

  • donquixote committed 8fb94a6 on 7.x-2.x
    Issue #2119537: JSON-LD breadcrumb for SERP.
    
donquixote’s picture

Status: Needs review » Fixed

For now this is not controlled by a setting.

This can be in a follow-up if need be.
For now it is good enough.

It is part of 7.x-2.7.!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.