How To Add Custom Meta Tag In Product View Page In Magento 2
In this post, I will guide you on How To Add Custom Meta Tag In Product View Page In Magento 2. Add many custom meta tags to the product view page to optimize SEO for the product.
With the below method, you can add as many meta tags as you want in just one code paragraph without having to create many custom blocks and you can add them to the default block.
What Is Meta Tag?
Meta tags are tags used in HTML and XHTML documents to provide structured metadata about a web page. They are part of a website’s tag and they can be read by search engines and web crawlers, so they can potentially help boost SEO.
Steps To Add Custom Meta Tag In Product View Page In Magento 2
1. Open the catalog_product_view.xml file by following the link below:
app\design\frontend\{your-Vendor}\{your-Theme}\Magento_Catalog\layout\catalog_product_view.xml
2. And add the following code:
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.additional">
<block class="Magento\Catalog\Block\Product\View" name="meta_type_name" template="Magento_Catalog::product/view/magetop_custom_meta_tags.phtml" />
</referenceBlock>
</body>
</page>
3. Create magetop_custom_meta_tags.phtml file in the following path:
app\design\frontend\{your-Vendor}\{your-Theme}\Magento_Catalog\templates\product\view\magetop_custom_meta_tags.phtml
4. Add the following code:
<meta property="og:your_custom_meta_tag_name" content="your_meta_tag_content" />
Then, run deploy static content, flush cache command and see the result:
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
Follow us for the more helpful posts!
We hope this is a useful post for you.
You can read more useful posts like How To Get Site Key And Secret Key From Google reCAPTCHA.
Thank you for reading!