• Hi,

    I’m currently building a custom theme using WordPress. I’ve only been starting to learn about WordPress and getting around it using HTML, CSS and Javascript (I’m new in the web coding world).

    I’d like to use jQuery library for my theme. At first I was thinking of using the normal <script> tag in my header.php and link to Google-hosted jQuery. After reading several blogs though, they said it’s a bad idea and might make things worse.

    I read about the post, and most recommend me to define a new function in my theme’s functions.php, like below

    function my_js() {
      wp_enqueue_script( 'jquery' );
      wp_enqueue_script( 'my-js-script', get_template_directory_uri() . '/js/default.js', 'jquery' );
    }    
    
    add_action('init', 'my_js');

    I tried using it, but I couldn’t get the result I wanted in default.js. I checked my header.php and there was no <script> tag there either.

    So.. how do I know whether the jQuery library has already been loaded? Is there something wrong with my script?

    I’ve also read about wp_register_script, but is it necessary to register script before using wp_enqueue_script?

    Cheers,
    aerlaut

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter aerlaut

    (@aerlaut)

    Thanks for the reply. I’ve checked out the page and fix my wp_enqueue_script (even copy-pasting to make sure), but there <script> tag isn’t even there..

    Any other suggestion why the jquery library does not load?

    (Badly tempted to just hard-code it to header.php)

    I guess, if you followed the codex instructions the libary is loaded, but your script is not, because: Yes, you need to hard code the scrpit that is supposed to run to the place where it is supposed to run. If that is the header section, than you put something like this ‘<script type=”text/javascript” src=”<?php bloginfo(‘template_directory’) ;?>/js/default.js”></script>’ directly beyond ‘<?php wp-head ();?>’. And check, if your footer is called by ‘<?php wp_footer ();?>’

    No – you enqueue the custom script.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to know JQuery is loaded’ is closed to new replies.