{"id":181,"date":"2018-09-14T13:07:37","date_gmt":"2018-09-14T13:07:37","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/09\/14\/override-product-view-page-social-meta-tags-in-magento-2\/"},"modified":"2025-05-22T17:19:28","modified_gmt":"2025-05-22T11:49:28","slug":"override-product-view-page-social-meta-tags-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/override-product-view-page-social-meta-tags-in-magento-2\/","title":{"rendered":"How to Override Product View Page Social Meta Tags in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Social Meta Tags allows store admin to control how the pages appear&nbsp;on social media. SEO best practice says to have unique social meta tags for each product page or category pages in Magento 2 store. Default Magento 2 provides social meta tags for the product pages, but sometimes a store owner may want to hide social meta tags or change the title, image or any other social meta tag content dynamically. In cases, you need to&nbsp;<em><strong>override product view page social meta tags in Magento 2.<\/strong><\/em> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation to override product view page social meta tags in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<strong>catalog_product_opengraph.xml<\/strong>&nbsp;file at&nbsp;<strong><strong>Vendor\\Extension\\view\\frontend\\layout<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;body>\n        &lt;referenceBlock name=\"opengraph.general\">\n            &lt;action method=\"setTemplate\">\n                &lt;argument name=\"template\" xsi:type=\"string\">Vendor_Extension::general.phtml&lt;\/argument>\n            &lt;\/action>\n        &lt;\/referenceBlock>\n    &lt;\/body>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<strong>general.phtml<\/strong>&nbsp;file at&nbsp;<strong><strong>Vendor\\Extension\\view\\frontend\\templates<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;meta property=\"og:type\" content=\"product\" \/>\n&lt;meta property=\"og:title\" content=\"&lt;?= $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getName())) ?>\" \/>\n&lt;meta property=\"og:image\" content=\"&lt;?= $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()) ?>\" \/>\n&lt;meta property=\"og:description\" content=\"&lt;?= $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getShortDescription())) ?>\" \/>\n&lt;meta property=\"og:url\" content=\"&lt;?= $block->escapeUrl($block->getProduct()->getProductUrl()) ?>\" \/>\n&lt;?php if ($priceAmount = $block->getProduct()->getFinalPrice()):?>\n    &lt;meta property=\"product:price:amount\" content=\"&lt;?= \/* @escapeNotVerified *\/ $priceAmount ?>\"\/>\n    &lt;?= $block->getChildHtml('meta.currency') ?>\n&lt;?php endif;?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A quick solution to dynamically override\u00a0<a href=\"https:\/\/meetanshi.com\/blog\/how-to-add-open-graph-meta-tags-to-magento-2\/\">social meta tags for Magento 2<\/a>\u00a0product pages!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Social Meta Tags allows store admin to control how the pages appear&nbsp;on social media. SEO best practice says to have unique social meta tags for&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":15599,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions\/15599"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}