First, register, then enqueue your JS script file in your /wp-content/themes/<your theme>/functions.php. In the following example, I’m registering a file called global.js. This file will hold your new jQuery code.
PHP
wp_register_script( 'global', get_stylesheet_directory_uri() . '/global.js');
wp_enqueue_script('wp_enqueue_scripts', get_stylesheet_directory_uri() . '/global.js', [], SITE_VERSION );
In your .js file, in my example I’m calling it global.js; use the function:
window.onload
JavaScript Example
window.onload = function(){
jQuery(document).ready(function () {
var scroll = $(window).scrollTop();
console.log("scroll: " + scroll);
});
})