Doing some searching through Google, I came across the same bit of code over and over for adding jQuery to a from-scratch Wordpress theme.
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
wp_enqueue_script('my_script', get_bloginfo('template_url') . '/js/theme.js', array('jquery'), '1.0', true);
}
I've added this code to my functions.php file, and I created a js folder and made a theme.js file using the following syntax in it:
jQuery(function ($) {
/* You can safely use $ in this code block to reference jQuery */
});
When I refresh my WP site, the theme.js file doesn't seem to be called. In Chrome Dev tools, it's not listed among the js files being rendered.
Am I using an outdated approach? How can I make my /js/theme.js file, using jquery, work for my theme?