window.onload wont execute in wordpress

Well don’t mix PHP and Javascript without the proper tags <script type=”text/javascript”> jQuery(document).ready(function( $ ){ if(location.href != “https://linestar.ca/contact-us/”) { alert(“Make sure you use the right contact Tab!”); } else { alert(“LineStar Welcomes You!”); } }); </script> As a sidenote, your website has lots of issues that you have to work out eventually.

using jQuery on only one page

You don’t need to add it on a template, you can use the wp_add_inline_script() function. It’d be something like: function tabs_enqueue() { if(is_page( 205 )) { wp_enqueue_script( ‘ui’, get_template_directory_uri() . ‘/js/ui/jquery-ui.min.js’, [], ‘1.8’, true); wp_add_inline_script( ‘ui’, ‘jQuery(window).load(function() { //code here });’ ); } } add_action(‘wp_enqueue_scripts’, ‘tabs_enqueue’); Hope it helps!

How to use jQuery in WordPress 5.7+

(I’m using 5.7.2) This is all you have to use: const $ = jQuery.noConflict();. However, you have to make sure the file you load is loaded after jQuery to prevent timing issues. So either make jQuery a dependency of your script like this: function _jf_load_scripts() { wp_register_script(‘main’, get_template_directory_uri() . ‘/build/js/main.bundle.js’, array(‘jquery’), MY_VERSION, TRUE); wp_enqueue_script(‘main’); } … Read more