How to get current page id through the plugin

This is my code.

/*
    Plugin Name: 
    Plugin URI:  
    Description: 
    Version:     
    Author:      
    Author URI:  
    License:     
    License URI: 
    Text Domain: 
    Domain Path: 
    */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$page_object = get_queried_object();
var_dump($page_object);

$page_id = get_queried_object_id();
echo $page_id;

I am geting >> Fatal error: Call to a member function get_queried_object() on a non-object in C:wampwwwwordpresswp-includesquery.php on line 45

Read more here: How to get current page id through the plugin

Leave a Reply

Your email address will not be published. Required fields are marked *