Magento: Displaying Custom Attributes on Product View

Adding custom attributes to your product view is very easy. Adding them to the product listing (category pages) is much more difficult. You’ll need to create a custom module for that. In this post though, I’ll only be showing you how to add attributes to the product view page.

If it is a text field (textbox or textarea), this is all you have to do:

<?php echo $_product->getAttributeName() ?>

There is one thing different here though. If your Attribute Code is “shirt_size”, then you would use getShirtSize(). Remove the underscores and capitalize the first letter of each word. It is picky that way. if you use getshirtsize(), it won’t work.

If you are using a dropdown or a multiple select, you have to call it a little differently:

<?php echo $_product->getAttributeText('shirt_size') ?>

This method requires the actual Attribute Code. If you are displaying the value from a dropdown, you’ll get exactly what you need with this call. If you are wanting to display the values from a multiple select, it will return an array.

This entry was posted in Magento. Bookmark the permalink.

50 Responses to Magento: Displaying Custom Attributes on Product View

  1. Melina says:

    Is it possible to call for the attribute’s name before the attribute’s value ?
    So that it also translates when there is a language selection made by the user….

    thank you!!!!

  2. Mike says:

    For everyone who is having the problem where number is displaying instead of the actual attribute data, this is the code you need:

    For the example Attribute: “shipping_unit”

    getProduct()->getAttributeText(‘shipping_unit’); ?>

    helper(‘catalog/output’)->productAttribute($this->getProduct(), $_shipping_unit, ‘shipping_unit’) ?>

    Should work perfectly! Took me 10 minute of puzzling to work this one out! 😉

  3. Peter says:

    Im using this code:
    htmlEscape($_product->getAttributeText(‘manufacturer’)); ?>

    but i want to add a link to it. so that when you clik on the attribute it opens a page showing all products with this attribute.

    Is that possible?

  4. Biju says:

    absolutely the solution that i have been searching for since last few hours. thank you so much for this great piece of code!

  5. Kalyan says:

    Hai friends i find this page as very useful.. but careful that themes also causing problem in displaying… if you are sure about the correctness of code but still not getting the output revert to the default theme and check it out…

    Thank u

  6. Aditya Mohan says:

    Great work ! ! Thanks a lot !!

  7. Sam says:

    My code looks the same; but on the front end I am seeing a number instead of the attribute; for example instead of Style: Garnet, It shows Style: 31.
    Any suggestions?

  8. thank you very much.
    you saved me a lot of time. =)

  9. John Deszell says:

    Where do I add this snippet of code to display on product page? I’ve found numerous posts on other sites saying go to:


    But when I look at my server via FTP, I don’t have any other folders after template in that breadcrumb.

    Any suggestions? I’m using 1.6 CE


  10. tuba says:

    Does anybody know how can I display attribute in the related product block?

  11. Ran says:

    Thanks Vishal. It works fine. catalog/output – to catalog/product do the trick…

  12. Vishal Sanwar says:

    solution of call custom attribute

    function getAttr($product_id, $attributeName) {
    $product = Mage::getModel(‘catalog/product’)->load($product_id);
    $attributes = $product->getAttributes();
    $attributeValue = null;
    if(array_key_exists($attributeName , $attributes)){
    $attributesobj = $attributes[“{$attributeName}”];
    $attributeValue = $attributesobj->getFrontend()->getValue($product);

    return $attributeValue;


  13. How to display custom attrubutes in magento ?

  14. ravi says:

    Very good article

  15. this wasn’t working for me until I removed the ‘quotes’ around shirt_size. If you’re having trouble with this in magento 1.4+, that may be your issue.

  16. omikron says:

    The attribute label doesn’t get translated when changing the store’s language.
    It’s interesting because the same attribute gets translated in the more info tab

    any ideas on how to solve this?

  17. Some times like in grouped.phtml you have to do it like this
    htmlEscape($_item->getAttributeText(‘contenance’)); ?>

  18. Hans says:

    Thanks, very useful.
    But I’m trying to call a custom attribute in the head section of my product page, and that’s not working with getAttributeName() ?>

    Do you have an idea how to call an attribute in the head section?

    • Josh Pratt says:

      Hans – The block that serves up the head of your page does not have access to the current product object. You’ll notice at the top of the view.phtml template, there is this line: $_product = $this->getProduct();. $this refers to the block that is loading up all of the data for the view template. I’m not sure why you’d want to get at product attributes in the head template… But, one thing you could try is Mage::registry(‘current_product’)->getData(‘attribute_code’). I haven’t tested it, but that may work…

      • Hans says:

        Hi Josh, I did notice the line to load the product in view.phtml, so I allready tried putting that line in the head.phtml but that didn’t work either.

        So I just tested the Mage::registry(‘current_product’)->getData(‘attribute_code’) code and that worked great, thanks again for that one!

        Now I can put my own specified canonical link to the products pages.

  19. Gavin says:

    Thanks for providing this.
    I noticed that if I had an attribute with ‘multiple select’ and in the admin only one option was selected it didn’t display the array.

    I’ve expanded the code in that scenario: [EDIT: Sorry, the code didn’t come through right…]

  20. Bampnet says:

    Why difficult? For retrieve attributes from category page here is the code:

    vehicle_type is the attribute code

  21. RBusiness says:

    I know this keeps getting rehashed but I’m not getting any results by using the code! I have everything set correctly from what I can tell.

    Modern Theme
    Cache OFF
    Attribute is set to display on product page!

    The attribute actually shows up in the TAB where it should. But I can’t get the data to repeat. I’ve got php skills too! It’s burning me here…

    My attribute is “bsc_brand_nm” I’m using…

    getBscBrandNm() ?>

    Anyone see an error that my eyes are blurring on?

    • Josh Pratt says:

      RBusiness – it appears that your code didn’t fully come through. I’ll email you, and if you could send me a pastebin of the code and let me know what type of attribute it is, I’ll try to help.

  22. Jeff says:

    muchos gracious, I’ve found this to be a very useful post!

  23. zdhkw says:

    It’s great! Thank you!

  24. Dennis says:

    isnt this posible in the xml files? I dont like changing the templates…

  25. Devin says:

    OH got it!

    Note to self (and others):

    $categoryFull = Mage::getModel(“catalog/category”)->load($this->getCurrentCategory()->getId());
    $attributes = $categoryFull->getAttributes();
    echo $attributes[‘your_custom_attribute’]->getFrontend()->getValue($categoryFull);

    This will get values of custom attributes for categories!

  26. Devin says:

    Any idea why this wont work on catelog->category->view.pthml when trying to call out category attributes? As I stated above, getAttributeText(‘my_attribute’) for category drop downs or multi-select wont work on category level..

    Very frustrating.

  27. pankaj says:

    How to get the product cost attribute value on reports .

    i need this product cost feild to be displayed on sales report and best sellers report.
    report–>sales–> sales report
    report–>Advanced–> bestsellers

    plz help its urgent.

  28. henri says:

    i created an attribute which is price attribute and i named it “retailprice”. I can see it in the additional information tab. How can i show it in the product list?

  29. Baldev says:

    Thank you so much for your valuable contribution

  30. Harry says:

    Thanks “ted”.
    Information provided by you helped me a lot.
    Thanks again…

  31. Devin says:

    great for product pages… however getAttributeText(”) for custom category attributes.. not so good.

    The attribute I just created is a drop down for categories, now getNAMEOFATTRIBUTE() returns a 1,2 or 3 (the total number of drop down options I have) but never the value of the selected attribute option. getAttributeText(”) as you stated is for drop downs returns nothing.

    Completely opposite for product pages though.

  32. ted says:

    i got it.. i had to enable ‘Used in product listing’ in the attribute settings.
    after enabling this, $_product->getNextShipmentDate() is not returning null anymore and showing the same value as in view.pthml.
    now i need to figure out how they format the date for display.

  33. ted says:

    using magento, how to get custom attributes in the /app/design/frontend/default/default/template/catalog/product/list.phtml intead of view.phtml.
    i want to show custom attributes in the product listing when people are searching for it.
    i tried using $_product->getNextShipmentDate() but it returns null in list.phtml. it returns the expected value in view.phtml.

  34. Bryan says:

    thank you soo much, this is exactly what I was looking for.

  35. Jefte says:

    Thank you for this little snippet. It was exactly what I was looking for. Is there a list of common functions for Magento like can be found in the WordPress codex? I find the Magento wiki to be… lacking.

  36. spuff says:

    Fantastic, thank you soooo much! How do people find out this stuff?

  37. Jaime says:

    and how for price fields?

  38. Srdjan says:

    Thanks.. I was wondering why my getAttributeText wasn’t working for the text field.

  39. Monkeyclaus says:

    Thanks so much for this great info. I used this to show an attribute on view.phtml that is a link. I see the link and my attribute but it is text rather than an active hyperlink. Any ideas ? Thanks for the wonderful resource Josh !

  40. Bivek says:

    I need to show select box of my new attributes(color/size). that i did by using above method.

    Now i need to show the attribute in shopping cart and also it must be shown in order details page how can i do that?

  41. Josh Pratt says:



  42. Astronomad says:

    What file is this in?