I do not understand the difference between the following two
get_current_screen
pagenow
Can you help me with that?
11 Answer
According to get_current_screenDocs:
it'll "return current screen object or null when screen not defined".
If you want to use it to detect admin pages, then use a different hook, for example you could use current_screen hook:
add_action('current_screen', 'detecting_current_screen');
function detecting_current_screen()
{ $current_screen = get_current_screen(); print_r($current_screen);
}Or
add_action('current_screen', 'detecting_current_screen');
function detecting_current_screen()
{ global $current_screen; print_r($current_screen);
}If you want to use it on the client-side and that returns null, then you could use a global variable called $pagenow.
Note: $pagenow will give you the template name.
global $pagenow;
echo $pagenow;Or
echo $GLOBALS["pagenow"];This should give you the name of the template you're on:
add_action( 'wp_footer', function () { global $pagenow; echo $pagenow;
}, 999 );If none of the methods, mentioned above, work for you, then you could use another global variable called $post.
Or
You could check your page by using:
1