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:
- 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.
- 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:
-
Navigate to
app/code/core/Mage/Cms/Block/Widget.php. -
Find the
getFormHtmlmethod. -
Within this method, locate the following line:
$block = new Varien_Data_Form(); -
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. -
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:

Adding Image Upload Fields
Next, let’s add an image upload field. We’ll follow a similar approach but use the image field type:
- Open the same
getFormHtmlmethod inapp/code/core/Mage/Cms/Block/Widget.php. - 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]', )); - Save and clear the cache again.

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!