Magento get current page title by store id or store code

Magento get current page title by store id or store code

September 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento get current page title by store id or store code

Retrieving Page Title by Store Code in Magento

In Magento, retrieving the current page title based on a specific store code or ID is a common requirement for various reasons such as analytics tracking or multi-language SEO optimization. While the built-in head block provides the title of the current selected view, it may not always cater to your needs when dealing with multiple stores.

Understanding the Challenge

Let’s first clarify the challenge at hand. The default Magento approach:

$title = Mage::getSingleton('core/layout')->getBlock('head')->getTitle();

returns the title of the current store view, which is determined by the user’s session or context. This might not be what you’re looking for if you want to get the page title for a specific store (like ‘en’ or ‘it’) regardless of the current selection.

The Magic of Mage::app()->getStore()

The key lies in manipulating Magento’s app instance and specifying the desired store before accessing its layout. Here’s an example:

$storeId = Mage::getModel('core/store')->load(1)->getId();
Mage::app()->setCurrentStore($storeId);

$layout = Mage::getSingleton('core/layout');
$block = $layout->createBlock('page/html_head');

// Now access the title for this specific store.
$title = $block->getTitle();

In this code, replace 1 with the ID of your desired store. The setCurrentStore() method temporarily sets Magento to use this store context.

A Note on Performance

While this approach works well in most cases, it’s essential to remember that changing the current store may have performance implications if done frequently within a single page load. This is because it reloads the entire store configuration into memory.

For better performance, especially when dealing with many stores, consider using Magento’s Mage_Core_Model_Store model directly:

$store = Mage::getModel('core/store')->loadByCode('en');
$titleBlock = $store->getTitle();

// Or use the store ID:
$storeId = 1;
$store = Mage::app()->getStore($storeId);
$titleBlock = $store->getTitle();

Conclusion

Retrieving a page title based on a specific Magento store involves temporarily setting that store as the current context and then accessing its layout block. This method ensures you get the correct title even if it differs from the currently selected view.

Remember to handle potential performance issues by minimizing the frequency of changing stores within a single request, especially in high-traffic environments.

For more advanced customizations like this, consider checking out our guide on Customizing Magento Layouts for further insights into how to manipulate blocks and layouts programmatically.

Performance Themes SEO

Our network