Support » Themes and Templates » Add jquery script the right way

  • Hello,

    I have a small script which needs jqueary, so I add this to my header:

    <script src=""></script>

    now it works, but I think it is not the right way to do it, I think it needs to be done with wp_enqueue_scripts

    but when I add this to function.php

    <?php function my_slider() {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', '');
        wp_enqueue_script( 'jquery' );
    	add_action('wp_enqueue_scripts', 'my_slider'); ?>

    it doesn’t work,
    so what do I forget?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Put:
    <?php wp_enqueue_script(“jquery”); ?>
    before the
    <?php wp_head(); ?> in your header.

    doesn’t work, is my script ok?

    What is your site’s url?

    it’s locally runned

    Your code looks good to me. The only thing I can think of is that you might be missing wp_head(); on your header.php file right before </head>

    Actually, I just noticed that you mention you put this on a file named function.php. The correct file name should be functions.php.

    That might be your problem after all.

    Try registering it as something other than ‘jquery’– something like ‘gjquery’. I have had trouble registering scripts if I use a name that matches something WordPress uses. I don’t know if it is a bug or feature 🙂 I haven’t had time to look into it much.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add jquery script the right way’ is closed to new replies.