Magento – Get the Attribute in details.phtml file on Product Page

attributescustom-attributesmagento2

I need to get my Attribute code and it should be printed its values on details.phtml in my theme's template.

I have tried below but no luck.

$attribute = $_product->getResource()->getAttribute('identifier'); 
if ($attribute) 
{ 
echo $attr_value = $attribute ->getFrontend()->getValue($_product); 
}

Any other ideas to get this?

Best Answer

Please make sure Visible on Catalog Pages on Storefront Attribute option set as Yes.

You can check this from backend Stores >> Attributes - Products. On Attribute Edit page, check the Visible on Catalog Pages on Storefront option in Storefront Properties Tab.

enter image description here