Magento call cms page through anchor tag from phtml file

Magento call cms page through anchor tag from phtml file

September 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento call cms page through anchor tag from phtml file

Linking CMS Pages in Magento via Anchor Tags

Magento provides robust functionality for managing Content Management System (CMS) pages right from the admin panel. If you want to link to one of these CMS pages using anchor tags within your PHTML templates, follow this comprehensive guide.

Understanding the CMS Page URL Structure

Before we dive into the code, let’s understand how Magento handles CMS page URLs. When you create a new CMS page in the admin panel, it assigns a unique identifier to that page. This identifier corresponds to the filename of the page. For example:

  • If your CMS page is named “About Us”, it will be saved as about_us.html by default.
  • You can change this filename while creating or editing the page.

Linking to a CMS Page via Anchor Tag

To link to a CMS page from within your PHTML file, you need to use Magento’s helper functions. Here’s how you can achieve this:

<?php echo $this->getUrl('cms/page/view', array('page_id' => 123)); ?>

In the code above:

  • getUrl() is a helper function that generates URLs in Magento.
  • The first parameter 'cms/page/view' refers to the CMS page view controller action.
  • The second parameter is an associative array containing additional parameters. In this case, we’re passing the ID of the desired CMS page.

Make sure you replace 123 with the actual ID of your target CMS page. You can find the IDs in the admin panel under Content > Pages.

If you want to use a friendly URL instead of the default Magento URL structure (which includes page_ID), you need to configure that first:

  1. Go to Stores > Configuration > General > Web.
  2. Scroll down to Search Engine Optimization.
  3. Set “Use Web Server Rewrites” to “Yes”.
  4. Click Save Config.

Getting a CMS Page URL Programmatically

If you want to get the URL of a specific CMS page programmatically within your PHTML file, use this helper function:

<?php echo $this->getUrl('cms/page/view noparam', array('page_id' => 123)); ?>

The noparam parameter tells Magento not to include any additional parameters in the URL.

Remember, always use these helper functions instead of hardcoding URLs. This approach ensures that your links remain functional even if you change the base URL or enable/disable rewrites.

Conclusion

Linking to CMS pages from your PHTML templates is a common task in Magento development. By understanding how Magento handles CMS page URLs and using its built-in helper functions, you can create robust, maintainable links with minimal effort.

For more advanced Magento customizations and tips, make sure to check out the official Magento documentation and explore our resources at Laravel Company.

Themes Admin

Our network