{"id":7198,"date":"2019-09-19T15:33:53","date_gmt":"2019-09-19T10:03:53","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7198"},"modified":"2019-09-27T11:42:27","modified_gmt":"2019-09-27T06:12:27","slug":"magento-2-check-current-url-homepage","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-check-current-url-homepage\/","title":{"rendered":"Magento 2 &#8211; How to Check Current URL is Homepage"},"content":{"rendered":"<p>In this post I am going to explain How to check IsHomePage in Magento 2.<\/p>\n<p>Add below code snippet in Block class.<\/p>\n<pre class=\"lang:default decode:true \">protected $_logo;\r\n\r\npublic function __construct(\r\n\t\\Magento\\Backend\\Block\\Template\\Context $context, \r\n\t\\Magento\\Theme\\Block\\Html\\Header\\Logo $logo, \r\n\tarray $data = []\r\n)\r\n{\r\n\t$this-&gt;_logo = $logo;\r\n\tparent::__construct($context, $data);\r\n}\r\n\r\npublic function isHomePage() {\r\n\treturn $this-&gt;_logo-&gt;isHomePage();\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Add below code snippet in template file.<\/p>\n<pre class=\"lang:default decode:true \">if ($block-&gt;isHomePage()) {\r\n    \/\/ do something\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Thats it. Enjoy Magento 2!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain How to check IsHomePage in Magento 2. Add below code snippet in Block class. protected $_logo; public function __construct( \\Magento\\Backend\\Block\\Template\\Context $context, \\Magento\\Theme\\Block\\Html\\Header\\Logo $logo, array $data = [] ) { $this-&gt;_logo = $logo; parent::__construct($context, $data); } public function isHomePage() { return $this-&gt;_logo-&gt;isHomePage(); } &nbsp; Add below code snippet&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-check-current-url-homepage\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7321,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[10,27],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7198"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=7198"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7198\/revisions"}],"predecessor-version":[{"id":7199,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7198\/revisions\/7199"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7321"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}