{"id":247,"date":"2016-02-25T21:18:28","date_gmt":"2016-02-25T15:48:28","guid":{"rendered":"http:\/\/www.magewallet.com\/?p=247"},"modified":"2020-03-13T16:09:37","modified_gmt":"2020-03-13T10:39:37","slug":"get-current-cms-page-id-magento2","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/get-current-cms-page-id-magento2\/","title":{"rendered":"How to get current CMS page id in Magento2"},"content":{"rendered":"<p>To get the id of current CMS page in Magento 2, use the following code snippet.<\/p>\n<pre class=\"lang:default decode:true \">protected $_page;\r\n\r\npublic function __construct(\r\n    ...\r\n    \\Magento\\Cms\\Model\\Page $page,\r\n    ...\r\n    array $data = []\r\n) {\r\n    parent::__construct($context, $data);\r\n    ...\r\n    $this-&gt;_page = $page;\r\n    ...\r\n}\r\n\r\nif ($this-&gt;_page-&gt;getId()) {\r\n    $pageId = $this-&gt;_page-&gt;getId();\r\n}<\/pre>\n<p>There are so many other methods to get CMS page details like title, identifier, content, and content heading. Lets check one by one.<\/p>\n<p>To get the identifier of the current CMS page you can use<\/p>\n<pre class=\"lang:default decode:true \">$pageIdentifier = $this-&gt;_page-&gt;getIdentifier();<\/pre>\n<p>To get the Page Title :<\/p>\n<pre class=\"lang:default decode:true \">$pageTitle = $this-&gt;_page-&gt;getTitle();<\/pre>\n<p>To get the Page Content :<\/p>\n<pre class=\"lang:default decode:true \">$pageContent = $this-&gt;_page-&gt;getContent();<\/pre>\n<p>To get the Page Content Heading:<\/p>\n<pre class=\"lang:default decode:true \">$pageContentHeading = $this-&gt;_page-&gt;getContentHeading();<\/pre>\n<p>Thats it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get the id of current CMS page in Magento 2, use the following code snippet. protected $_page; public function __construct( &#8230; \\Magento\\Cms\\Model\\Page $page, &#8230; array $data = [] ) { parent::__construct($context, $data); &#8230; $this-&gt;_page = $page; &#8230; } if ($this-&gt;_page-&gt;getId()) { $pageId = $this-&gt;_page-&gt;getId(); } There are so many other methods to get CMS&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/get-current-cms-page-id-magento2\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":4894,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[76,10],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/247"}],"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=247"}],"version-history":[{"count":3,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions"}],"predecessor-version":[{"id":10501,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions\/10501"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/4894"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}