get the current page id in wordpress 1

get the current page id in wordpress

$page_id = get_queried_object_id();

Here is what the above code is Doing:
1. We’re getting the current page ID.
2. We’re checking if the current page has a parent.
3. If it does, we’re getting the parent’s ID.
4. If it doesn’t, we’re getting the current page’s ID.

Similar Posts