Hello friends, welcome to my another blog post how to load inline script after main jQuery in WordPress. If you want to load your inline scripts after main jQuery then what to do. I had a previous blog how to enqueue inline scripts in header where I show you how to load js script using functions.php. But here I show you a conditional statement. If your main js files load then your inline js will load otherwise not. Some times we have to add some inline js scripts to initialize some js functionality. So we need this types of condition. WordPress has a function wp_script_is to check if a script has been registered, enqueued, printed, or is waiting to be printed. So this function did the trick for me.
Copy the below code to your theme’s functions.php and change accordingly to your requirements.
Load Inline Script After main jQuery
Here I load inline script after main jQuery in header using hook(wp_head). We can use wp_footer hook to load inline script after main jQuery in footer. Try the above code. This will solve your problem. Now you know how to load inline script after main jQuery in header or footer. If you have any question or suggestion please comment below. If you like my post then please share it with your friends. Thank you.