Running jQuery code after deferred loading jQuery Library in WordPress

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);
    });
})

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x