I want to put JavaScript code on certain pages in frontend. But the output return null .
add_action( 'wp_footer', function () {
$screen = get_current_screen();
var_dump( $screen );
}, 999 );
I want to put JavaScript code on certain pages in frontend. But the output return null .
add_action( 'wp_footer', function () {
$screen = get_current_screen();
var_dump( $screen );
}, 999 );
get_current_screen
is an Admin API, it can't be used on the frontend, only in /wp-admin
screens.
If you want to run javascript code only on certain pages, either enqueue it on those pages, or load it on all pages and check the body classes, or many other methods. get_current_screen
is not the way to do it.