WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've written a pretty simple jQuery script, and I don't know how to call it. It's in its own directory.

First, how do I register it, and then how do I enqueue it?

I assume that's the order it's done in, and that registering it basically means that it's available for use, and that enqueuing it applies it.

I know that I have to add code to functions.php, but not sure exactly what. I've read a few things that haven't made it any clearer. For instance, WP.org says if I want to use Google's jQuery library, then I should deregister WP's install. Someone on this forum says don't deregister it. Using WP's version is fine, so this is what I have in functions.php:

function my_scripts_method() {
    wp_register_script( 'jquery' );
    wp_enqueue_script( 'jquery' );

add_action('wp_enqueue_scripts', 'my_scripts_method');

I also don't know how to call it on a page. What code, specifically, would I add to the page's WYSIWYG to get the script to work? Here's what I have on the page now:

<?php wp_register_script( $resize_fade.js, $http://www.mysite.com/subdirectory/wp-content/js/, ); ?>
share|improve this question
up vote 0 down vote accepted

i usally first deregister to avoid duplicates, then register it and enqueue it like so:

function my_scripts_method() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
    wp_enqueue_script( 'jquery' );
add_action('wp_enqueue_scripts', 'my_scripts_method');

Hope this helps,

share|improve this answer
I'd had that code before. My real concern is what code to put in my page to make it work. And does it go in the WYSIWYG editor, or directly into a .php page? And is the code I wrote correct? – Adam Mar 31 '12 at 17:58
You put this entire script as is in your functions.php in your template files... Thats all. it would load jquery at the background of each wordpress file. – Sagive SEO Mar 31 '12 at 18:02
Including the other code I'm asking about, where it has the name and path to the script? – Adam Mar 31 '12 at 18:13
My script includes everything you need... it would work just like that. if you want to use your own jquery (which is a bit slower) you should replace "ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"; which the url of your file. but i would reccomend you use it like it is. – Sagive SEO Mar 31 '12 at 18:30
I have that. Now, how do I make the script I wrote work on the page? Did you see it? I tried to add <?php wp_register_script( $resize_fade.js, $mysite.com/subdirectory/wp-content/js, ); ?> to the page, not knowing wether or not that was right. BTW, I do appreciate your help... – Adam Mar 31 '12 at 22:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.