{"id":341049,"date":"2022-06-26T07:07:05","date_gmt":"2022-06-26T07:07:05","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=341049"},"modified":"2024-06-18T13:56:55","modified_gmt":"2024-06-18T13:56:55","slug":"get-admin-path-in-magento-2-programmatically","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/","title":{"rendered":"Get Admin path in Magento 2 programmatically"},"content":{"rendered":"\n<p>Hello Guys!!!<br><br>In this article, we are going to learn how we can get an admin path\/URI programmatically.<br><br>Here, we can get the admin URI by using the following ways:<\/p>\n\n\n\n<p><strong>1.  By using AreaList:<\/strong> In this method, we will create an instance of <em>\\Magento\\Framework\\App\\AreaList<\/em> class and call the <em>getFrontName<\/em> method as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n$areaList = $objectManager-&gt;get(&quot;\\Magento\\Framework\\App\\AreaList&quot;);\n$adminPath = $areaList-&gt;getFrontName(&#039;adminhtml&#039;);<\/pre>\n\n\n\n<p><strong>2. By using Backend Helper: <\/strong>In this method, we will create an instance of  <em>\\Magento\\Backend\\Helper\\Data <\/em>class and call the <em>getAdminFrontName<\/em> method as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n$backendHelper = $objectManager-&gt;get(&quot;\\Magento\\Backend\\Helper\\Data&quot;);\n$adminPath = $backendHelper-&gt;getAdminFrontName();<\/pre>\n\n\n\n<p><strong>Note: <\/strong>The above-mentioned 1st method may not work in some cases, then you can go for the 2nd method. For example, if you have set wild card DNS entry settings for your instance and want to display a Magento admin login page link at frontend pages and frontend stores URLs may be like: <\/p>\n\n\n\n<p><em>https:\/\/maindomain.com<\/em> or <em>https:\/\/xyz.maindomain.com<\/em> then, in this case, in the first case, for URL <em>https:\/\/xyz.maindomain.com<\/em>, you will not get any value for admin path URL, then you can use 2nd method(using Backend helper).<\/p>\n\n\n\n<p><strong>3. By using CLI:<\/strong> You can execute the following command in CLI to get the admin path URI:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">php bin\/magento info:adminuri<\/pre>\n\n\n\n<p>After executing the above command, the result will be as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">Admin URI: \/admin_webkul<\/pre>\n\n\n\n<p>Hope this will be helpful.<br>Thanks \ud83d\ude42<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Guys!!! In this article, we are going to learn how we can get an admin path\/URI programmatically. Here, we can get the admin URI by using the following ways: 1. By using AreaList: In this method, we will create an instance of \\Magento\\Framework\\App\\AreaList class and call the getFrontName method as follows: 2. By using <a href=\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":249,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[12858,12860,12854,12853,12856,12857,12855],"class_list":["post-341049","post","type-post","status-publish","format-standard","hentry","category-magento2","tag-admin-path","tag-admin-uri","tag-get-admin-frontname","tag-get-admin-path","tag-get-admin-path-programmatically","tag-get-admin-uri","tag-get-backend-frontname"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get Admin path in Magento 2 programmatically - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Admin path in Magento 2 programmatically - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Hello Guys!!! In this article, we are going to learn how we can get an admin path\/URI programmatically. Here, we can get the admin URI by using the following ways: 1. By using AreaList: In this method, we will create an instance of MagentoFrameworkAppAreaList class and call the getFrontName method as follows: 2. By using [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-26T07:07:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-18T13:56:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Khushboo Sahu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khushboo Sahu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\"},\"author\":{\"name\":\"Khushboo Sahu\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\"},\"headline\":\"Get Admin path in Magento 2 programmatically\",\"datePublished\":\"2022-06-26T07:07:05+00:00\",\"dateModified\":\"2024-06-18T13:56:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\"},\"wordCount\":214,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"Admin path\",\"Admin URI\",\"get admin frontname\",\"get admin path\",\"get admin path programmatically\",\"get admin URI\",\"get backend frontname\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\",\"url\":\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\",\"name\":\"Get Admin path in Magento 2 programmatically - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2022-06-26T07:07:05+00:00\",\"dateModified\":\"2024-06-18T13:56:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Admin path in Magento 2 programmatically\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\",\"name\":\"Khushboo Sahu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Khushboo Sahu\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Admin path in Magento 2 programmatically - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/","og_locale":"en_US","og_type":"article","og_title":"Get Admin path in Magento 2 programmatically - Webkul Blog","og_description":"Hello Guys!!! In this article, we are going to learn how we can get an admin path\/URI programmatically. Here, we can get the admin URI by using the following ways: 1. By using AreaList: In this method, we will create an instance of MagentoFrameworkAppAreaList class and call the getFrontName method as follows: 2. By using [...]","og_url":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2022-06-26T07:07:05+00:00","article_modified_time":"2024-06-18T13:56:55+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Khushboo Sahu","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Khushboo Sahu","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/"},"author":{"name":"Khushboo Sahu","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca"},"headline":"Get Admin path in Magento 2 programmatically","datePublished":"2022-06-26T07:07:05+00:00","dateModified":"2024-06-18T13:56:55+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/"},"wordCount":214,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["Admin path","Admin URI","get admin frontname","get admin path","get admin path programmatically","get admin URI","get backend frontname"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/","url":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/","name":"Get Admin path in Magento 2 programmatically - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2022-06-26T07:07:05+00:00","dateModified":"2024-06-18T13:56:55+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/get-admin-path-in-magento-2-programmatically\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get Admin path in Magento 2 programmatically"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca","name":"Khushboo Sahu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Khushboo Sahu"},"url":"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/341049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/249"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=341049"}],"version-history":[{"count":2,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/341049\/revisions"}],"predecessor-version":[{"id":448614,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/341049\/revisions\/448614"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=341049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=341049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=341049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}