Organizational Research By

Surprising Reserch Topic

adding jquery and custom scripts to a wordpress theme

adding jquery and custom scripts to a wordpress theme  using -'jquery,wordpress,wordpress-theming'

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_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://", false, null);
   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?

asked Oct 13, 2015 by sumit_jaiswalmca
0 votes

Related Hot Questions

1 Answer

0 votes
answered Oct 13, 2015 by rajeevr642