{"id":4535,"date":"2016-05-03T12:56:40","date_gmt":"2016-05-03T11:56:40","guid":{"rendered":"https:\/\/www.utilewebsites.nl\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/"},"modified":"2016-05-03T12:56:40","modified_gmt":"2016-05-03T11:56:40","slug":"bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html","status":"publish","type":"wz_knowledgebase","link":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/","title":{"rendered":"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html"},"content":{"rendered":"<p>  There is a small bug in Magento 2.0.4 if there is no meta description of a product, Magento by default takes the product description but does not strip it so that all the html tags are out. Find the file : vendor\\magento\\module-catalog\\Block\\Product\\View.php and the code below<\/p>\n<pre class=\"lang-php prettyprint prettyprinted\"><code>\n$currentCategory = $this-&gt;_coreRegistry-&gt;registry('current_category');\n137if ($keyword) {\n138    $this-&gt;pageConfig-&gt;setKeywords($keyword);\n139} elseif ($currentCategory) {\n140    $this-&gt;pageConfig-&gt;setKeywords($product-&gt;getName());\n141}\n142$description = $product-&gt;getMetaDescription();\n143if ($description) {\n144    $this-&gt;pageConfig-&gt;setDescription($description);\n145} else {\n146   <span style=\"color: #3366ff;\"> $this-&gt;pageConfig-&gt;setDescription($this-&gt;string-&gt;substr($product-&gt;getDescription(), 0, 255));\n<\/span>147}\n148if ($this-&gt;_productHelper-&gt;canUseCanonicalTag()) {\n149    $this-&gt;pageConfig-&gt;addRemotePageAsset(\n150        $product-&gt;getUrlModel()-&gt;getUrl($product, ['_ignore_category' =&gt; true]),\n151        'canonical',\n152        ['attributes' =&gt; ['rel' =&gt; 'canonical']]\n153    );\n154}\n155\n\n156$pageMainTitle = $this-&gt;getLayout()-&gt;getBlock('page.main.title');\n\n<\/code><\/pre>\n<p>Change the indicated line in blue to : $this-&gt;pageConfig-&gt;setDescription($this-&gt;string-&gt;substr(strip_tags($product-&gt;getDescription()), 0, 255));<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a small bug in Magento 2.0.4 if there is no meta description of a product, Magento by default takes the product description but does not strip it so that all the html tags are out. Find the file : vendor\\magento\\module-catalog\\Block\\Product\\View.php and the code below $currentCategory = $this-&gt;_coreRegistry-&gt;registry('current_category'); 137if ($keyword) { 138 $this-&gt;pageConfig-&gt;setKeywords($keyword); 139} elseif ($currentCategory) { 140 $this-&gt;pageConfig-&gt;setKeywords($product-&gt;getName()); 141} 142$description = $product-&gt;getMetaDescription(); 143if ($description) { 144 $this-&gt;pageConfig-&gt;setDescription($description); 145} else { 146 $this-&gt;pageConfig-&gt;setDescription($this-&gt;string-&gt;substr($product-&gt;getDescription(), 0, 255)); 147} 148if ($this-&gt;_productHelper-&gt;canUseCanonicalTag()) { 149 $this-&gt;pageConfig-&gt;addRemotePageAsset( 150 $product-&gt;getUrlModel()-&gt;getUrl($product, ['_ignore_category' =&gt; true]), 151 'canonical', 152 ['attributes' =&gt; ['rel' =&gt; 'canonical']] 153 ); 154} 155 156$pageMainTitle&nbsp;<a href=\"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/\" class=\"read-more\">Continue Reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"wzkb_product":[],"wzkb_category":[61],"wzkb_tag":[],"class_list":["post-4535","wz_knowledgebase","type-wz_knowledgebase","status-publish","hentry","wzkb_category-magento-2-0-x"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bug When meta description is empty magento 2.0.4 gets products description but does not strip html - Utilewebsites<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html - Utilewebsites\" \/>\n<meta property=\"og:description\" content=\"There is a small bug in Magento 2.0.4 if there is no meta description of a product, Magento by default takes the product description but does not strip it so that all the html tags are out. Find the file : vendormagentomodule-catalogBlockProductView.php and the code below $currentCategory = $this-&gt;_coreRegistry-&gt;registry(&#039;current_category&#039;); 137if ($keyword) { 138 $this-&gt;pageConfig-&gt;setKeywords($keyword); 139} elseif ($currentCategory) { 140 $this-&gt;pageConfig-&gt;setKeywords($product-&gt;getName()); 141} 142$description = $product-&gt;getMetaDescription(); 143if ($description) { 144 $this-&gt;pageConfig-&gt;setDescription($description); 145} else { 146 $this-&gt;pageConfig-&gt;setDescription($this-&gt;string-&gt;substr($product-&gt;getDescription(), 0, 255)); 147} 148if ($this-&gt;_productHelper-&gt;canUseCanonicalTag()) { 149 $this-&gt;pageConfig-&gt;addRemotePageAsset( 150 $product-&gt;getUrlModel()-&gt;getUrl($product, [&#039;_ignore_category&#039; =&gt; true]), 151 &#039;canonical&#039;, 152 [&#039;attributes&#039; =&gt; [&#039;rel&#039; =&gt; &#039;canonical&#039;]] 153 ); 154} 155 156$pageMainTitle&nbsp;Continue Reading\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/\" \/>\n<meta property=\"og:site_name\" content=\"Utilewebsites\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\\\/\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\\\/\",\"name\":\"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html - Utilewebsites\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#website\"},\"datePublished\":\"2016-05-03T11:56:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Knowledge Base\",\"item\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/\",\"name\":\"Utilewebsites\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#organization\",\"name\":\"Utilewebsites\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/logo-Utilewebsites-2017.png\",\"contentUrl\":\"https:\\\/\\\/www.utilewebsites.nl\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/logo-Utilewebsites-2017.png\",\"width\":3000,\"height\":593,\"caption\":\"Utilewebsites\"},\"image\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html - Utilewebsites","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/","og_locale":"en_US","og_type":"article","og_title":"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html - Utilewebsites","og_description":"There is a small bug in Magento 2.0.4 if there is no meta description of a product, Magento by default takes the product description but does not strip it so that all the html tags are out. Find the file : vendormagentomodule-catalogBlockProductView.php and the code below $currentCategory = $this-&gt;_coreRegistry-&gt;registry('current_category'); 137if ($keyword) { 138 $this-&gt;pageConfig-&gt;setKeywords($keyword); 139} elseif ($currentCategory) { 140 $this-&gt;pageConfig-&gt;setKeywords($product-&gt;getName()); 141} 142$description = $product-&gt;getMetaDescription(); 143if ($description) { 144 $this-&gt;pageConfig-&gt;setDescription($description); 145} else { 146 $this-&gt;pageConfig-&gt;setDescription($this-&gt;string-&gt;substr($product-&gt;getDescription(), 0, 255)); 147} 148if ($this-&gt;_productHelper-&gt;canUseCanonicalTag()) { 149 $this-&gt;pageConfig-&gt;addRemotePageAsset( 150 $product-&gt;getUrlModel()-&gt;getUrl($product, ['_ignore_category' =&gt; true]), 151 'canonical', 152 ['attributes' =&gt; ['rel' =&gt; 'canonical']] 153 ); 154} 155 156$pageMainTitle&nbsp;Continue Reading","og_url":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/","og_site_name":"Utilewebsites","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/","url":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/","name":"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html - Utilewebsites","isPartOf":{"@id":"https:\/\/www.utilewebsites.nl\/en\/#website"},"datePublished":"2016-05-03T11:56:40+00:00","breadcrumb":{"@id":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/bug-when-meta-description-is-empty-magento-2-0-4-gets-products-description-but-does-not-strip-html\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.utilewebsites.nl\/en\/"},{"@type":"ListItem","position":2,"name":"Knowledge Base","item":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/"},{"@type":"ListItem","position":3,"name":"Bug When meta description is empty magento 2.0.4 gets products description but does not strip html"}]},{"@type":"WebSite","@id":"https:\/\/www.utilewebsites.nl\/en\/#website","url":"https:\/\/www.utilewebsites.nl\/en\/","name":"Utilewebsites","description":"","publisher":{"@id":"https:\/\/www.utilewebsites.nl\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.utilewebsites.nl\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.utilewebsites.nl\/en\/#organization","name":"Utilewebsites","url":"https:\/\/www.utilewebsites.nl\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.utilewebsites.nl\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.utilewebsites.nl\/wp-content\/uploads\/2019\/08\/logo-Utilewebsites-2017.png","contentUrl":"https:\/\/www.utilewebsites.nl\/wp-content\/uploads\/2019\/08\/logo-Utilewebsites-2017.png","width":3000,"height":593,"caption":"Utilewebsites"},"image":{"@id":"https:\/\/www.utilewebsites.nl\/en\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wz_knowledgebase\/4535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wz_knowledgebase"}],"about":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/types\/wz_knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/comments?post=4535"}],"version-history":[{"count":0,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wz_knowledgebase\/4535\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/media?parent=4535"}],"wp:term":[{"taxonomy":"wzkb_product","embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wzkb_product?post=4535"},{"taxonomy":"wzkb_category","embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wzkb_category?post=4535"},{"taxonomy":"wzkb_tag","embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wzkb_tag?post=4535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}