Magento 2 – Get Custom Attribute Title and Value in phtml File

custom-attributesfrontendmagento2

Magento 2 how to get custom attribute title and its value in phtml file.

Best Answer

As per your comments, I assume that you are getting the product object.

Then use:

$attribute = $_product->getResource()->getAttribute('attribute_code');

This will give the attribute object, where attribute_code is the attribute code.

then use the following code to get the value of attribute for current product:

$attribute->getFrontend()->getValue($_product);

and use below code to get the name (label) of the attribute:

$attribute->getFrontendLabel();