Magento how to add extra fields for static block

Magento how to add extra fields for static block

September 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento how to add extra fields for static block

Adding Custom Fields to Magento Static Blocks

If you’re looking to enhance your Magento website’s flexibility and make it easier for non-technical users to update content, adding custom fields to static blocks is a great solution. In this post, we’ll guide you through the process of adding both simple text fields and image upload fields to your static blocks.

Why Add Custom Fields?

Before diving into the code, let’s understand why this is useful:

  1. Ease of updates: By providing dedicated fields for content entry, you make it easier for your marketing team or content managers to update the website, reducing dependency on developers.
  2. Consistency in layout: Predefined fields help maintain a consistent format and structure across pages.

Adding Simple Text Fields

Let’s start with adding a simple text field. Here are the steps:

  1. Navigate to app/code/core/Mage/Cms/Block/Widget.php.

  2. Find the getFormHtml method.

  3. Within this method, locate the following line:

    $block = new Varien_Data_Form();
    
  4. Add your custom field right after this line:

    $fieldset = $block->addFieldset('cms_block_fieldset');
    $fieldset->addField('my_custom_text', 'text', array(
       'label'     => Mage::helper('cms')->__('My Custom Text Field'),
       'required'  => false,
       'name'      => 'block[content]',
    ));
    

    Replace 'my_custom_text' with the name you’d like to give your field, and adjust the label text as needed.

  5. Save your changes and clear your cache: php bin/magento cache:clean.

Now, when editing a static block in the admin panel, you’ll see your new custom text field:

Magento Static Block with Custom Text Field

Adding Image Upload Fields

Next, let’s add an image upload field. We’ll follow a similar approach but use the image field type:

  1. Open the same getFormHtml method in app/code/core/Mage/Cms/Block/Widget.php.
  2. After adding your text field, continue with:
    $fieldset->addField('my_image_field', 'image', array(
       'label'     => Mage::helper('cms')->__('Image'),
       'required'  => false,
       'name'      => 'block[background_image]',
    ));
    
  3. Save and clear the cache again.

Magento Static Block with Image Upload Field

Conclusion

Adding custom fields to Magento static blocks is a powerful way to enhance your website’s content management capabilities. By following these steps, you can easily create both text and image upload fields without extensive coding.

Remember, it’s essential to keep your Magento version up-to-date for the latest features and security patches. For more advanced customizations and enterprise-level solutions, consider reaching out to a professional Magento development agency like Laravel Company.

Happy coding!

Themes

Our network