Skip to main content

Magento 2 Get Current CMS Page Id

Today, we will discuss how we can get current CMS page id using code.

Below is an example.
protected $_page;

public function __construct(
...
\Magento\Cms\Model\Page $page
,
...
array $data
= []
) {
parent
::__construct($context, $data);
...
$this
->_page = $page;
...
}

if ($this->_page->getId()) {
$pageId
= $this->_page->getId();
}

Thank You.!

Comments

Popular posts from this blog

Magento 2 Set Title And Meta Title In Page Programatically

We can set different Meta Title and Page Heading programatically. I am giving you example. Refer below example - public function __construct ( \Magento\Framework\View\Element\Template\Context $context , \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig , \Magento\Framework\View\Page\Config $pageConfig , $data = array () ) { $this -> _scopeConfig = $scopeConfig ; $this -> _pageConfig = $pageConfig ; parent :: __construct ( $context , $data ); } /** * Prepare global layout * * @return $this */ protected function _prepareLayout () { $this -> _pageConfig -> addBodyClass ( 'advance-sitemap' ); if ( $this -> getSeoTitle ()) $this -> _pageConfig -> getTitle ()-> set ( 'Meta Title' ); if ( $this -> getMetaKeywords ()) $this -> _pageConfig -> setKeywords ( 'Meta Keywords' ); if ( $this -> getMetaDescription ()) $this -&g

Remove SID (session ID) from URL in Magento 2

Before removing SID (session ID) we should have knowledge why Magento uses SID (session ID) . Use SID on Frontend — Set to Yes if you want a user to stay logged in while switching between stores. Go to the Stores > Configuration > General > Web > Session Validation Settings > Use SID on Storefront and set its value to No   Thank You.!

Magento 2 Disable Minicart functionality Completely

The Cart Sidebar is often called the  mini cart  and displays a summary of the items in the cart. It is enabled by default and appears when you click the number of items in the Cart Link.   To Disable Mini cart Sidebar follow below steps - On the Admin sidebar, click  Stores . In the  Settings  section, choose  Configuration . In the  Sales  section on the left panel, choose  Checkout . Expand the  Shopping Cart Sidebar  section. Set  Display Shopping Cart Sidebar to No . Click  Save Config . Thank You.!