Please tell me how to properly connect your script in WordPress before the built-in jQuery ?

I do it this way, but nothing happens. I add code to functions.php :

 function my_scripts_method() { wp_enqueue_script('common', get_template_directory_uri(). '/js/common.js', array('jquery')); } add_action('wp_enqueue_scripts', 'my_scripts_method'); 

The common.js file:

 jQuery(document).ready(function($) { $(function() { $(".rslides").responsiveSlides(); }); function windowSize() { if ($(window).width() <= '650') { $('.top_cont').detach().insertAfter('.nav_menu'); document.getElementById("name").placeholder = "Ваше имя"; document.getElementById("phone").placeholder = "Телефон"; } else { $('.nav_menu').detach().insertAfter('.top_cont'); document.getElementById("name").placeholder = "Введите имя"; document.getElementById("phone").placeholder = "Введите номер телефона"; } if ($(window).width() <= '650') { $('.cen').detach().insertAfter('.prem'); $('.cen').detach().insertAfter('.usl'); } else {} } $(window).load(windowSize); $(window).resize(windowSize); }); 
  • There are no visual errors in the code. check the path to the script file. and make sure the script itself works, regardless of cms - lexxl

1 answer 1

First, see if the script is registered in the header, and second, try connecting a newer version of jquery

 function new_jquery() { wp_deregister_script( 'jquery-core' ); wp_register_script( 'jquery-core', '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'); wp_enqueue_script( 'jquery' ); } add_action('new_v_jquery', 'new_jquery');