how to get sku and product name on the head.php page?

how to get sku and product name on the head.php page?

August 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
how to get sku and product name on the head.php page?

Getting SKU and Product Name on the Head.php Page

When working with Magento, it’s often necessary to access product data like SKU or name within specific pages such as head.php. However, this isn’t always straightforward due to the page’s nature and context.

The head.php file is responsible for rendering meta tags and other head elements of a page. It doesn’t directly have access to product objects as it usually operates independently of the storefront.

Understanding the Head Block

The Mage_Page_Block_Html_Head block in Magento 1.x uses the _data property to hold any additional data passed from the controller during block instantiation. This includes things like the current product object ($this->_data['product']) if a product is being displayed.

Accessing Product Data

To access product data like SKU or name, you must first ensure that the product object is properly set in the _data property of your head block. This typically occurs when the block is instantiated from within a controller action that handles a specific product.

Let’s say you have a controller action that loads a product:

public function viewAction()
{
    $productId = (int)$this->getRequest()->getParam('id');
    $product = Mage::getModel('catalog/product')->load($productId);

    if (!$product) {
        $this->_forward('no-route');
        return;
    }

    // Add the product to _data for later use
    $this->getLayout()->getBlock('head')->setData('product', $product);
}

In this example, we load a product by ID and then pass it as data to our head block. This allows us to access $this->_data['product'] within the head.php file.

Retrieving SKU and Product Name

Now, in your head.php file, you can use the following methods:

// Get SKU
$sku = $this->getData('product')->getSku();

// Get product name
$name = $this->getData('product')->getName();

Remember that these calls will only work if the setData method was called in your controller and the product object is correctly set.

Caching Considerations

Be aware of caching implications. If your head.php file is cached, changes to this data won’t be immediately visible until the cache expires or is cleared manually.

Conclusion

While it’s not a standard use case, you can access product data in the head block by passing the product object from the controller as additional data. Ensure that the data is properly set and the correct methods are used to retrieve the required information.

For more advanced customizations of Magento head blocks and meta data, consider exploring Laravel Company’s Magento Development Services. Our team specializes in optimizing Magento performance and implementing complex business logic.

Magento 1 Catalog Themes SEO

Our network