---
title: "Magento 2: Check if the Current URL is HomePage"
url: "https://magecomp.com/blog/magento-2-check-if-the-current-url-is-homepage/"
date: "2021-12-20T15:19:40+00:00"
modified: "2025-02-19T05:31:46+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 213
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Sometimes you are not aware about the current page. Check whether the Current URL is HomePage or not in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Implement Multiselect Filter for Order Status in Magento 2 Order Grid"
    url: "https://magecomp.com/blog/how-to-implement-multiselect-filter-for-order-status-in-magento-2-order-grid/"
  - title: "How to Display Image in Custom Module using Form Field in Magento 2"
    url: "https://magecomp.com/blog/display-image-in-custom-module-using-form-field-in-magento-2/"
  - title: "Magento 2: Add Readonly Field in ui_component Form"
    url: "https://magecomp.com/blog/magento-2-add-readonly-field-in-ui-component-form/"
---

# Magento 2: Check if the Current URL is HomePage

_Published: December 20, 2021_  
_Author: Dhiren Vasoya_  

![Check if the Current URL is HomePage in m2](https://magecomp.com/blog/wp-content/uploads/2021/12/Check-if-the-Current-URL-is-HomePage-in-m2-1024x512.webp)

**Hello Magento Friends,**

Today I am going to explain How to Check if the Current URL is HomePage in Magento 2.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-2.webp)](https://magecomp.com/services/hyva-theme-development/)

If you are not sure whether a current page is a homepage or not, this article will guide you to check the current URL in Magento 2.
## Steps to Check if the Current URL is HomePage in Magento 2:
**Step 1:** Use the below code in your block class
**app\code\Vendor\Extension\Block\Homepage.php**

```
<?php
namespace VendorExtensionBlock;
class Homepage extends MagentoFrameworkViewElementTemplate
{
   protected $logo;
   public function __construct(
		     MagentoBackendBlockTemplateContext $context,
		     MagentoThemeBlockHtmlHeaderLogo $logo,
		     array $data = []
	   )
   {
		     $this->logo = $logo;
		     parent::__construct($context, $data);
   }

   // Check if current url is home page or not
    public function isHomePage()
    {
		     return $this->logo->isHomePage();
    }
}
?>
```

**Step 2:** Declare function in template (.phtml) file
**app\code\Vendor\Extension\view\frontend\templates\ homepage.phtml**

```
<?php

if ($block->isHomePage())
{
     echo “Hii ! This is Home Page.”;
}

?>
```

## [![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Conclusion:
This way simply you can Check if the Current URL is HomePage in Magento 2. Learn [**How to Configure Store URLs in Magento 2**](https://magecomp.com/blog/configure-store-urls-magento-2/). In case of any difficulty, let me know via the comment part. Share the article and stay in touch with us for more Magento solutions.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2023/10/Magento-2-Speed-Performance-Optimization-Services-CTA-4.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/magento-2-check-if-the-current-url-is-homepage/](https://magecomp.com/blog/magento-2-check-if-the-current-url-is-homepage/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-01 08:17:35 UTC_  
