get the current page id in wordpress

To get the current page ID in WordPress, you can use the following code:

$page_id = get_the_ID();

Explanation: 1. The get_the_ID() function is a WordPress template tag that retrieves the ID of the current post or page within the WordPress Loop.

  1. When you call get_the_ID(), it returns the ID of the current post or page.

  2. By assigning the result of get_the_ID() to the $page_id variable, you can then use the variable $page_id to refer to the current page ID in your WordPress template or plugin code.