1

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 );
1
  • 2
    get_current_screen() won’t do anything on the front end. It’s for getting the admin screen. What value do you need? Commented Sep 15, 2021 at 20:37

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.