Add custom property to magento Attributes and display it on the front end

Add custom property to magento Attributes and display it on the front end

August 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add custom property to magento Attributes and display it on the front end

Extending Magento Attributes: Add Custom Properties for Front-end Display

Magento is an incredibly powerful e-commerce platform that allows developers to extend its core functionality with ease. One of the most common ways to customize your product catalog is by adding custom attributes and properties. In this post, we’ll guide you through the process of creating a custom attribute in Magento 2 and displaying its value on the front-end product page.

Creating a Custom Attribute

First, let’s create a new text field attribute for our products. To do this, navigate to Stores > Attributes > Product. Click on the “Add New Attribute” button at the top right corner of the screen.

In the “Add New Attribute” form:

  • Set the “Attribute Code” to something unique, like custom_description.
  • Choose “Text Field” as the “Catalog Input Type for Store Owner”.
  • Check the box next to “Visible on Product View Page on Front-end” to display the attribute on the product page.
  • Click the “Save Attribute” button.

Modifying the Product Templates

By default, Magento doesn’t know how to display custom attributes. We need to tell it where and how to show our new custom_description field.

Step 1: Locate the Product View Template

The product view template is located in the default theme under app/design/frontend///Magento_Catalog/templates/product/view. The file we’re interested in is called product.view.phtml.

Step 2: Add Your Custom Attribute to the Templates

Open the product.view.phtml file and locate this line of code:

<?= $block->getProductDetailsHtml() ?>

Right after this line, paste the following code snippet:

<?php if ($block->hasOptions()): ?>
    <div class="product options">
        <h2><?= /* @escapeNotVerified */ $block->getAttributeTitle('custom_description') ?></h2>
        <?= /* @escapeNotVerified */ $block->getAttributeValue('custom_description') ?>
    </div>
<?php endif; ?>

This code checks if the product has any options (which our custom attribute is considered to be). If it does, we display a new section called “Options” and populate it with our custom_description field.

Assigning Values to Your Custom Attribute

To assign values to your new attribute, navigate back to Catalog > Products. Select the product you want to modify. In the “Product Information” section, find the “Custom Attributes” tab. Here, you’ll see a new field called “Custom Description”. Enter your desired text for this field and click “Save”.

Displaying Custom Properties

By default, Magento doesn’t allow you to add custom properties like “Weight” or “Size” to attributes. To achieve this, you would need to create an additional module that extends the core attribute functionality.

Check out this guide from Laravel Company on creating a custom Magento 2 extension for more advanced customizations like these.

Conclusion

Adding custom attributes in Magento is an excellent way to extend the platform’s functionality and tailor your product catalog to your specific needs. By following this guide, you now know how to create a new attribute and display its value on the front-end product page.

Remember that Magento offers extensive documentation and resources for developers. If you’re looking to take your Magento skills to the next level, consider checking out the Laravel Company blog for more in-depth tutorials and best practices.

Happy coding!

Magento 2 Catalog API Themes

Our network