I am update OG tag for home page,


 <meta property="og:image" content="http://example.com/DEFAULTIMAGE.png" />
 <meta name="og:title" content="Printing coop is a most famous Digital Printing certer"/>
 <meta name="og:description" content="Printing coop is a most famous Digital Printing certer in Montreal Canada.Professional Printer Services."/>

How to apply for my Category, Products, and CMS Pages & blocks?

1 Answer 1


For instance take a look for Product OG in .../vendor/magento/module-catalog/view/frontend/layout/catalog_product_opengraph.xml

You will find this :

<?xml version="1.0"?>
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <attribute name="prefix" value="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# product: http://ogp.me/ns/product#" />
        <referenceBlock name="head.additional">
            <block class="Magento\Catalog\Block\Product\View" name="opengraph.general" template="Magento_Catalog::product/view/opengraph/general.phtml">
                <block class="Magento\Directory\Block\Currency" name="opengraph.currency" as="meta.currency" template="Magento_Catalog::product/view/opengraph/currency.phtml"/>

You can overwrite this template Magento_Catalog::product/view/opengraph/general.phtml in your theme


 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

/** @var $block \Magento\Catalog\Block\Product\View */

<meta property="og:type" content="product" />
<meta property="og:title"
      content="<?= /* @noEscape */ $block->stripTags($block->getProduct()->getName()) ?>" />
<meta property="og:image"
      content="<?= $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()) ?>" />
<meta property="og:description"
      content="<?= /* @noEscape */ $block->stripTags($block->getProduct()->getShortDescription()) ?>" />
<meta property="og:url" content="<?= $block->escapeUrl($block->getProduct()->getProductUrl()) ?>" />
<?php if ($priceAmount = $block->getProduct()->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)->getAmount()) :?>
    <meta property="product:price:amount" content="<?= $block->escapeHtmlAttr($priceAmount) ?>"/>
    <?= $block->getChildHtml('meta.currency') ?>
<?php endif;?>

And for Categories etc.. you can use the product as an example you can add a template to head.additional block

  • Magento_Catalog::product/view/opengraph/general.phtml --> what is the path? My current project path like app/design/frontend/Zero_theme/my_theme/Magento_Catalog/
    – zus
    Feb 8, 2021 at 12:21
  • To overwrite the file in your them it would be like: app/design/frontend/Zero_theme/my_theme/Magento_Catalog/templates/product/view/opengraph/general.phtml Feb 8, 2021 at 12:25
  • I have couple of doubts, 1) After added the given script to general.phtml anything else still i need to do, i mean should i update into any xml file, can you pls help me with this 2) For category can you pls guide me.
    – zus
    Feb 9, 2021 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.