{"id":6098,"date":"2016-09-08T13:59:34","date_gmt":"2016-09-08T13:59:34","guid":{"rendered":"https:\/\/blog.mageworx.com\/?p=6098"},"modified":"2023-03-17T14:15:49","modified_gmt":"2023-03-17T14:15:49","slug":"extending-rich-snippets-functionality-in-magento-2","status":"publish","type":"post","link":"https:\/\/www.mageworx.com\/blog\/extending-rich-snippets-functionality-in-magento-2","title":{"rendered":"Hiding the Default Rich Snippets Functionality in Magento 2"},"content":{"rendered":"\n<!-- SEO Ultimate (http:\/\/www.seodesignsolutions.com\/wordpress-seo\/) - Code Inserter module -->\n<!-- Google Tag Manager (noscript) -->\r\n<noscript><iframe src=\"https:\/\/www.googletagmanager.com\/ns.html?id=GTM-5DTCW7B8\"\r\nheight=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"><\/iframe><\/noscript>\r\n<!-- End Google Tag Manager (noscript) -->\n<!-- \/SEO Ultimate -->\n\n<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> 3<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><p>If you\u2019ve come to this page, you must know what Rich Snippets are and how they work in Magento 2.<\/p>\n<p>Upon the whole, the <a href=\"https:\/\/www.mageworx.com\/magento-2-seo-extension.html\">structured data markup<\/a>\u00a0is quite a cool feature of the second version of the eCommerce platform. <a href=\"https:\/\/schema.org\">Schema.org<\/a> was added as the default template, which lets merchants equip their site search results with price, <a href=\"https:\/\/www.mageworx.com\/magento2-product-reviews-and-ratings.html\">rating<\/a>, reviews, or other markup values in just a few clicks.<\/p>\n<p>There are, however, some cases when you may want to disable the default rich snippets functionality. The reasons for that can be:<!--more--><\/p>\n<ul>\n<li><strong>price format issues<\/strong> \u2014 currently, the format used by Magento 2 doesn\u2019t correspond to the latest schema.Org requirements, which may trigger the following error:<strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6108\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/1-1.png\" alt=\"1\" width=\"942\" height=\"271\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/1-1.png 942w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/1-1-600x173.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/1-1-768x221.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/strong><\/li>\n<\/ul>\n<ul>\n<li><strong>conflicts<\/strong> with some 3-d party structured data markup extensions,<\/li>\n<li><strong>issues with Google products<\/strong> \u2014 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.<\/li>\n<\/ul>\n<p>Unfortunately, up to v.2.1.1, it\u2019s impossible to disable the default rich snippets functionality via the <em>Config settings<\/em>. Hence, you need some workaround solution.<\/p>\n<p>In this article, I\u2019ll tell you how to disable the default structured data markup via creating a a little, yet very useful extension for Magento 2.<\/p>\n<p>First, let\u2019s create the extension\u2019s environment.<\/p>\n<ol>\n<li>\n<h3><strong>Creating the Extension<\/strong><\/h3>\n<\/li>\n<\/ol>\n<p>Let\u2019s call it \u2018<em>Owner_Custom<\/em>\u2019\u00a0 (although, you can choose any name you wish).<\/p>\n<p>Next, go to app\/code and create an \u2018<em>Owner<\/em>\u2019 folder there. Inside of this folder, create a new one, named \u2018<em>Custom<\/em>\u2019 \u2014 it will be the root folder for our extension.<\/p>\n<p>From in here, we create the following files:<\/p>\n<p><em>FILE: registration.php<\/em><\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true\">&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    'Owner_Custom',\n    __DIR__\n);<\/pre>\n<p><em>FILE: etc\/module.xml<\/em><\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\"?&gt;\n&lt;config xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\"&gt;\n&lt;module name=\"Owner_Custom\" setup_version=\"0.0.1\"\/&gt;\n&lt;\/config&gt;<\/pre>\n<p>At the next step, install the extension via Console:<\/p>\n<p><em>php bin\/magento setup:upgrade \u00a0&#8212; keep-generated\u00a0 <\/em><\/p>\n<p>All done, now our extension can be found on the list of all modules under the Admin panel:<\/p>\n<p><em>php bin\/magento module:status\u00a0 <\/em><\/p>\n<h3><strong>2. Removing the default data markup<\/strong><\/h3>\n<p>When the extension\u2019s environment is ready, we can get down to creating a layout file, where all the magic takes place.<\/p>\n<p><em>FILE:\u00a0view\/frontend\/layout\/catalog_product_view.xml<\/em><\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true\">&lt;?xml version=\"1.0\"?&gt;\n&lt;page xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\"&gt;\n    &lt;body&gt;\n        &lt;attribute name=\"itemtype\" remove=\"true\" ifconfig=\"mageworx_seo\/markup\/product\/rs_enabled\"\/&gt;\n        &lt;attribute name=\"itemscope\" remove=\"true\" ifconfig=\"mageworx_seo\/markup\/product\/rs_enabled\"\/&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;\n<\/pre>\n<p>IMPORTANT<\/p>\n<p>Don\u2019t forget to update cache each time you make change to the file.<\/p>\n<p>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.:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6109\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/2-1.png\" alt=\"2\" width=\"942\" height=\"186\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/2-1.png 942w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/2-1-600x118.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/2-1-768x152.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/p>\n<p>As you can see, after this manipulation, Google stops throwing any warnings in the \u2018<em>Offer<\/em>\u2019 section.<\/p>\n<p>Let\u2019s add some more code lines:<\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true\">&lt;?xml version=\"1.0\"?&gt;\n&lt;page xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\"&gt;\n    &lt;body&gt;\n        &lt;attribute name=\"itemtype\" remove=\"true\"\/&gt;\n        &lt;attribute name=\"itemscope\" remove=\"true\"\/&gt;\n        &lt;referenceBlock name=\"product.price.final\"&gt;\n            &lt;arguments&gt;\n                &lt;argument name=\"zone\" xsi:type=\"boolean\"&gt;false&lt;\/argument&gt;\n            &lt;\/arguments&gt;\n        &lt;\/referenceBlock&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;<\/pre>\n<p>By adding these piece, we\u2019ve removed the parameter that was responsible for marking up this block as an \u2018Offer\u2019. As a result, Google tools don\u2019t detect any data that could be used for Rich Snippets here:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6110\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/3-1.png\" alt=\"3\" width=\"937\" height=\"69\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/3-1.png 937w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/3-1-600x44.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/3-1-768x57.png 768w\" sizes=\"auto, (max-width: 937px) 100vw, 937px\" \/><\/p>\n<p>And there is one final touch left to do.<\/p>\n<p>In order to disable the default rich snippets for all product types, you need to add 2 more files. This one for downloadable products:<\/p>\n<p><em>FILE:\u00a0view\/frontend\/layout\/catalog_product_view_type_downloadable.xml<\/em><\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true\">&lt;?xml version=\"1.0\"?&gt;\n&lt;page xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\"&gt;\n    &lt;body&gt;\n        &lt;referenceContainer name=\"product.price.final.copy\"&gt;\n            &lt;arguments&gt;\n                &lt;argument name=\"zone\" xsi:type=\"boolean\"&gt;false&lt;\/argument&gt;\n            &lt;\/arguments&gt;\n        &lt;\/referenceContainer&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;\n<\/pre>\n<p>And this is for bundle products:<\/p>\n<p><em>FILE: view\/frontend\/layout\/catalog_product_view_type_bundle.xml<\/em><\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true\">&lt;?xml version=\"1.0\"?&gt;\n&lt;page xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\"&gt;\n    &lt;body&gt;\n        &lt;referenceBlock name=\"product.price.render.bundle.customization\"&gt;\n            &lt;arguments&gt;\n                &lt;argument name=\"zone\" xsi:type=\"boolean\"&gt;false&lt;\/argument&gt;\n            &lt;\/arguments&gt;\n        &lt;\/referenceBlock&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;\n<\/pre>\n<p>IMPORTANT<\/p>\n<p>Note that if some of the products in your Magento store has already been reviewed, this review will be included into the default markup. This may trigger the following error:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7156\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/31e6d408642cc8cc288f6fde6f6fb0d8.png\" alt=\"31e6d408642cc8cc288f6fde6f6fb0d8\" width=\"894\" height=\"184\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/31e6d408642cc8cc288f6fde6f6fb0d8.png 894w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/31e6d408642cc8cc288f6fde6f6fb0d8-600x123.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2016\/09\/31e6d408642cc8cc288f6fde6f6fb0d8-768x158.png 768w\" sizes=\"auto, (max-width: 894px) 100vw, 894px\" \/><br \/>\nSince it\u2019s hardcoded in the Magento theme files, to delete it, you have to rewrite this file:<\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true \">vendor\/magento\/module-review\/view\/frontend\/templates\/helper\/summary.phtml<\/pre>\n<p>Copy the file content into:<\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true \">app\/design\/frontend\/[package]\/[theme]\/templates\/helper\/summary.phtml<\/pre>\n<p>and delete the markup:<\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true \">(itemprop=\u201caggregateRating\u201d itemscope itemtype=\u201chttps:\/\/schema.org\/AggregateRating\u201d ; itemprop=\u201cbestRating\u201d ; itemprop=\u201cratingValue\u201d ; itemprop=\u201creviewCount\u201d )<\/pre>\n<p>As a result, you should get this (for Magento 2.1x) :<\/p>\n<pre class=\"theme:github font:courier-new font-size:16 line-height:18 lang:default decode:true \">&lt;?php\n\/**\n * Copyright \u00a9 2016 Magento. All rights reserved.\n * See COPYING.txt for license details.\n *\/\n\n\/\/ @codingStandardsIgnoreFile\n\n?&gt;\n&lt;?php $url = $block-&gt;getReviewsUrl() . '#reviews'; ?&gt;\n&lt;?php $urlForm = $block-&gt;getReviewsUrl() . '#review-form'; ?&gt;\n&lt;?php if ($block-&gt;getReviewsCount()): ?&gt;\n&lt;?php $rating = $block-&gt;getRatingSummary(); ?&gt;\n&lt;div class=\"product-reviews-summary&lt;?php echo !$rating ? ' no-rating' : ''?&gt;\"&gt;\n    &lt;?php if ($rating):?&gt;\n    &lt;div class=\"rating-summary\"&gt;\n         &lt;span class=\"label\"&gt;&lt;span&gt;&lt;?php \/* @escapeNotVerified *\/ echo __('Rating') ?&gt;:&lt;\/span&gt;&lt;\/span&gt;\n         &lt;div class=\"rating-result\" title=\"&lt;?php \/* @escapeNotVerified *\/ echo $rating; ?&gt;%\"&gt;\n             &lt;span style=\"width:&lt;?php \/* @escapeNotVerified *\/ echo $rating; ?&gt;%\"&gt;&lt;span&gt;&lt;span&gt;&lt;?php \/* @escapeNotVerified *\/ echo $rating; ?&gt;&lt;\/span&gt;% of &lt;span&gt;100&lt;\/span&gt;&lt;\/span&gt;&lt;\/span&gt;\n         &lt;\/div&gt;\n     &lt;\/div&gt;\n    &lt;?php endif;?&gt;\n    &lt;div class=\"reviews-actions\"&gt;\n        &lt;a class=\"action view\" href=\"&lt;?php \/* @escapeNotVerified *\/ echo $url ?&gt;\"&gt;&lt;span&gt;&lt;?php \/* @escapeNotVerified *\/ echo $block-&gt;getReviewsCount() ?&gt;&lt;\/span&gt;&amp;nbsp;&lt;span&gt;&lt;?php \/* @escapeNotVerified *\/ echo($block-&gt;getReviewsCount() == 1) ? __('Review') : __('Reviews') ?&gt;&lt;\/span&gt;&lt;\/a&gt;\n        &lt;a class=\"action add\" href=\"&lt;?php \/* @escapeNotVerified *\/ echo $urlForm ?&gt;\"&gt;&lt;?php \/* @escapeNotVerified *\/ echo __('Add Your Review') ?&gt;&lt;\/a&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n&lt;?php elseif ($block-&gt;getDisplayIfEmpty()): ?&gt;\n&lt;div class=\"product-reviews-summary empty\"&gt;\n    &lt;div class=\"reviews-actions\"&gt;\n        &lt;a class=\"action add\" href=\"&lt;?php \/* @escapeNotVerified *\/ echo $urlForm; ?&gt;\"&gt;\n            &lt;?php \/* @escapeNotVerified *\/ echo __('Be the first to review this product') ?&gt;\n        &lt;\/a&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n&lt;?php endif; ?&gt;<\/pre>\n<p>And finally, this is how you can enable\/disable our custom extension:<\/p>\n<p><em>php bin\/magento module:enable Owner_Custom<\/em><br \/>\n<em>php bin\/magento module:disable Owner_Custom<\/em><\/p>\n<p>Ah, and don\u2019t forget to refresh cache to make all the changes take into effect.<\/p>\n<p>That\u2019s basically it.<\/p>\n<p>Should you have any questions on this topic, feel free to leave your comments in the section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> 3<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span>If you\u2019ve 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\u00a0is 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 [&hellip;]<\/p>\n","protected":false},"author":47,"featured_media":14712,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[255,425],"tags":[436],"class_list":{"0":"post-6098","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-magento-2","8":"category-magento-how-tos","9":"tag-developer-diaries"},"_links":{"self":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts\/6098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/comments?post=6098"}],"version-history":[{"count":16,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts\/6098\/revisions"}],"predecessor-version":[{"id":16646,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts\/6098\/revisions\/16646"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/media\/14712"}],"wp:attachment":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/media?parent=6098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/categories?post=6098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/tags?post=6098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}