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

  • which type of custom attribute is it ? product,customer and where do you want to get value ( page ) Commented Sep 11, 2018 at 11:23
  • Its just custom attribute i need to display its title and value in product detail page.. Commented Sep 11, 2018 at 11:27
  • what type of attribute is it ? text, select etc ? Commented Sep 11, 2018 at 11:27
  • Text attribute... Commented Sep 11, 2018 at 11:29
  • blog.chapagain.com.np/… just visit this link Commented Sep 11, 2018 at 11:39

3 Answers 3


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:


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


You can get attribute label and attribute value as below

$myAttr = $_product->getResource()->getAttribute('my_attribute');

if ($myAttr){

    // Get Value
    $attrValue = $myAttr->getFrontend()->getValue($_product);

    // Get Label
    $attrLabel = $myAttr->getStoreLabel();

Go to :


find your attribute and click to open edit page and select "Storefront Properties"

And from there "Allow HTML Tags on Storefront" select to Yes.

Then on your template you can get value by $product->getYourAttributeCode()

NOTE : if your attribute is like custom_attribute then your method will be like $product->getCustomAttribute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.