How to add H2 for Short Description of Product Under Magento 2.4?

To change the HTML format you can call your custom phtml file and make the changes because the attribute.phtml is called for more than one attibute.

so a better option is to create your file and make the HTML related changes over there.

 

First, you need to override the XML file as per your example code. Only thing is that you need to change the template with your custom template.

you can create a template phtml file in your custom module as well as in your custom theme and add a path for the file in XML.

 

app/design/frontend/Prescriptionglasses/safetyglasses/Magento_Catalog/layout/catalog_product_view.xml

<referenceBlock name=”product.info.overview” template=”Magento_Catalog::product/view/custom_template.phtml”>
</referenceBlock>

app/design/frontend/Prescriptionglasses/safetyglasses/Magento_Catalog/templates/product/view/custom_template.phtml

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

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis

/**
* Product view template
*
* @var $block \Magento\Catalog\Block\Product\View\Description
*/
?>
<?php
$_helper = $this->helper(Magento\Catalog\Helper\Output::class);
$_product = $block->getProduct();

if (!$_product instanceof \Magento\Catalog\Model\Product) {
return;
}

$_call = $block->getAtCall();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

$renderLabel = true;
// if defined as ‘none’ in layout, do not render
if ($_attributeLabel == ‘none’) {
$renderLabel = false;
}

if ($_attributeLabel && $_attributeLabel == ‘default’) {
$_attributeLabel = $_product->getResource()->getAttribute($_code)->getStoreLabel();
}
if ($_attributeType && $_attributeType == ‘text’) {
$_attributeValue = ($_helper->productAttribute($_product, $_product->$_call(), $_code))
? $_product->getAttributeText($_code)
: ”;
} else {
$_attributeValue = $_helper->productAttribute($_product, $_product->$_call(), $_code);
}
?>

<?php if ($_attributeValue) :?>
<div class=”product attribute <?= $block->escapeHtmlAttr($_className) ?>”>
<?php if ($renderLabel) :?>
<h2 class=”type”><?= $block->escapeHtml($_attributeLabel) ?></h2>
<?php endif; ?>
<div class=”value” <?= /* @noEscape */ $_attributeAddAttribute ?>><?= /* @noEscape */ $_attributeValue ?></div>
</div>
<?php endif; ?>

Referance file: vendor\magento\module-catalog\view\frontend\templates\product\view\attribute.phtml

You can modify and customize this file as per your requirement because this file is only affected your short description not anywhere else.