Magento - check if cms page

Magento - check if cms page

July 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - check if cms page

Checking if a Page is a CMS Page in Magento

Hello developers! Today we’re going to tackle an essential task in Magento - checking if a page is a CMS (Content Management System) page. This is particularly useful when you want to apply different breadcrumbs or styling for your CMS pages compared to regular product or category pages.

Understanding the Problem

Let’s break down the issue first. In Magento, CMS pages are stored differently than other types of pages like categories or products. The standard approach for generating breadcrumbs doesn’t differentiate between these page types by default.

Our friend Rito here has already started working on the breadcrumbs.phtml file, but he’s stuck at the crucial step - determining if a given page is indeed a CMS page.

How to Check if a Page is a CMS Page

The key lies in understanding how Magento identifies page types. In this case, we can leverage the core_router module which contains an array of valid routes for different page types, including ‘cms’ for CMS pages.

Here’s how you can check if a given page is a CMS page using PHP:

<?php
$isCMSPage = Mage::getModel('core/url_rewrite')->loadByRoutePath('cms', $this->getRequest()->getPathInfo());
if ($isCMSPage && !empty($isCMSPage->getId())) {
    // This is a CMS page!
} else {
    // This is not a CMS page
}
?>

In this code snippet, we’re using Magento’s core/url_rewrite model to load the URL rewrite record for the current route path. If a valid record exists for the ‘cms’ route type (i.e., it’s a CMS page), we know that the page is indeed a CMS page.

A Better Approach with Custom Controllers

While the above method works, it’s not the most efficient or clean way to handle this in a long-term production environment. A better approach would be to create custom controllers for your CMS pages and use the built-in Magento functionalities to differentiate them from other page types.

For example, you could create a new controller class like Mage_Cms_IndexController and override the indexAction() method to include any specific logic required for CMS pages. You can then map this controller to the ‘cms’ route in your config files.

This approach provides better separation of concerns and makes your code more maintainable and scalable. It’s a great way to ensure that your customizations are properly isolated from the core Magento functionalities.

Conclusion

Checking if a page is a CMS page in Magento isn’t as straightforward as it seems at first glance, but with the right knowledge, it becomes quite manageable. Whether you choose to use the direct PHP check or opt for a more robust solution with custom controllers, remember that understanding how Magento handles different page types is key.

If you’re looking for more insights and best practices on Magento development, I highly recommend checking out our blog at LaravelCompany.com. We cover everything from e-commerce solutions to advanced Magento tutorials.

Catalog Extensions Themes SEO

Our network