Magento move currency symbol out of span for microformats

Magento move currency symbol out of span for microformats

October 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento move currency symbol out of span for microformats

Moving Currency Symbol Out of Span for Microformats in Magento

Are you facing microformat errors due to currency symbols being enclosed within span tags in your Magento store? In this post, we’ll dive into the core currency helper function used in Magento and show you how to elegantly remove the currency symbol from within the span tag.

Understanding the Currency Helper Function

The currency function is a core helper method provided by Magento to format and display prices. The parameters passed to it determine the output:

  • $_price: The price value to be formatted.
  • true, true: These are the precision settings. The first false indicates no rounding is performed, while the second true means that trailing zeros will not be removed.

The current implementation of this function in Magento 1.7.0.2 outputs the currency symbol within a span tag:

<?php echo $_coreHelper->currency($_price, true, true) ?>

Which generates HTML like this:

<span class="price">£100.00</span>

The Microformat Challenge

Microformats rely on properly structured semantic markup to provide machine-readable information about a web page’s content. By enclosing the currency symbol within the span tag, we’re breaking these microformat conventions and causing validation errors.

To resolve this issue while preserving the current styling, we need to move the currency symbol out of the span tag:

£<span class="price">100.00</span>

The Solution: Customizing the Currency Helper

To achieve this, you can create a custom extension that overrides the core currency function with your own implementation.

  1. Create a new module: Create a new Magento module in your app/code/local directory following the standard Magento structure (e.g., Namespace_Modulename).

  2. Override the currency helper: In your module, create app/code/local/Namespace/Modulename/etc/config.xml and add the following code to extend the core Mage_Core_Helper_Data class:

<config>
    <global>
        <helpers>
            <core>
                <rewrite>
                    <currency>Namespace_Modulename_Helper_Data</currency>
                </rewrite>
            </core>
        </helpers>
    </global>
</config>
  1. Implement the custom currency function: Create app/code/local/Namespace/Modulename/Helper/Data.php and implement your custom currency method:
<?php

class Namespace_Modulename_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function currency($price, $precision = null)
    {
        if ($precision === true) {
            // Custom logic to handle precision settings
        } else {
            return '£' . number_format(Mage::helper('directory')->currencyConvert($price), $precision);
        }
    }
}
  1. Apply the custom helper: In your template file (app/design/frontend/default/default/template/catalog/product/price.phtml), replace the existing <?php echo $_coreHelper->currency($_price, true, true) ?> line with:
<?php echo $this->helper('namespace_modulename')->currency($_price, true, true) ?>

Now, when you load your product page, the currency symbol will be removed from the span tag while maintaining the desired presentation.

Conclusion

By understanding and customizing Magento’s core currency helper function, we’ve successfully resolved a common microformat validation issue. This approach allows us to maintain our existing styling and formatting rules without breaking any core functionality.

Remember, when overriding core functions, it’s essential to use proper version control and keep your code organized to avoid conflicts during future updates. For more advanced customizations and best practices in Magento development, feel free to explore the extensive resources available at Laravel Company.

Happy coding!

Magento 1 Configuration Pricing Errors

Our network