Tweet about this on TwitterShare on Facebook0Share on Google+1Share on LinkedIn16Email this to someoneBuffer this page

If you’ve come to this page, you must know what Rich Snippets are and how they work in Magento 2.

Upon the whole, the structured data markup  is quite a cool feature of the second version of the eCommerce platform. Schema.org was added as the default template, which lets merchants equip their site search results with price, rating, reviews or other markup values in just a few-clicks.

There are, however, some cases when you may want to disable the default rich snippets functionality. The reasons for that can be:

  • price format issues — currently, the format used by Magento 2 doesn’t correspond to the latest schema.Org requirements, which may trigger the following error:1
  • conflicts with some 3-d party structured data markup extensions,
  • issues with Google products — this type of products may come with a different price (e.g. MSRP), which, in turn, triggers conflicts with the default Magento 2 rich snippets.

Unfortunately, up to v.2.1.1, it’s impossible to disable the default rich snippets functionality via the Config settings. Hence, you need some workaround solution.

In this article, I’ll tell you how to disable the default structured data markup via creating a a little, yet very useful extension for Magento 2.

First, let’s create the extension’s environment.

  1. Creating the Extension

Let’s call it ‘Owner_Custom’  (although, you can choose any name you wish).

Next, go to app/code and create an ‘Owner’ folder there. Inside of this folder, create a new one, named ‘Custom’ — it will be the root folder for our extension.

From in here, we create the following files:

FILE: registration.php

FILE: etc/module.xml

 

At the next step, install the extension via Console:

php bin/magento setup:upgrade  — keep-generated 

All done, now our extension can be found on the list of all modules under the Admin panel:

php bin/magento module:status 

2. Removing the default data markup

When the extension’s environment is ready, we can get down to creating a layout file, where all the magic takes place.

FILE: view/frontend/layout/catalog_product_view.xml

IMPORTANT

Don’t forget to update cache each time you make change to the file.

In this part of the code, we are going to change the parameters that are used for formatting structured data markup. After we implement this, the markup will contain only our offer, e.g.:

2

As you can see, after this manipulation, Google stops throwing any warnings in the ‘Offer’ section.

Let’s add some more code lines:

By adding these piece, we’ve removed the parameter that was responsible for marking up this block as an ‘Offer’. As a result, Google tools don’t detect any data that could be used for Rich Snippets here:

3

And there is one final touch left to do.

In order to disable the default rich snippets for all product types, you need to add 2 more files. This one for downloadable products:

FILE: view/frontend/layout/catalog_product_view_type_downloadable.xml

And this is for bundle products:

FILE: view/frontend/layout/catalog_product_view_type_bundle.xml

And finally, this is how you can enable/disable our custom extension:

php bin/magento module:enable Owner_Custom
php bin/magento module:disable Owner_Custom

Ah, and don’t forget to refresh cache to make all the changes take into effect.

That’s basically it.

Should you have any questions on this topic, feel free to leave your comments in the section below.

Tweet about this on TwitterShare on Facebook0Share on Google+1Share on LinkedIn16Email this to someoneBuffer this page