Question

Is there a way to show all meta keywords for a product on its product detail page. something looks like below? enter image description here

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. enter image description here

Was it helpful?

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
scroll top