Show Product Meta Keywords in Product pages
-
14-04-2021 - |
Question
Is there a way to show all meta keywords for a product on its product detail page. something looks like below?
I'm currently able to display the meta-keyword attribute values under the email icon( I added the following code at the end of the mailto.phtml).
<div class="tags">
<hr />
<b><?php echo $_product->getData('meta_keyword'); ?></b>
</div>
However, I want to display them like the image above ( in individual box) and move them underneath product title.
Solution
You can reach this by creating catalog_product_view.xml
layout in your custom module and add your block into product.info.main
container like:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.main">
<block class="Magento\Catalog\Block\Product\View" name="meta_keywords" template="Test_Module::meta_keywords.phtml" before="-" />
</referenceContainer>
</body>
</page>
meta_keywords.phtml template:
<?php /** @var \Magento\Catalog\Block\Product\View $block */ ?>
<?= $block->escapeHtml($block->getProduct()->getData('meta_keywords')) ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange