Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
wp_register_script('SliderViewer', '/js/SliderViewer-1.2.js');
wp_enqueue_script('SliderViewer');

get_header();

however, mydomain.com/js/SliderViewer-1.2.js doesn't exist.

My js is in the ftp at

thewebsite -> wp-content -> themes -> BLANK-Theme -> js

What's the path of that? Thanks-

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You're registering/enqueueing your script wrong. You should register/enqueue in your theme's functions.php file instead of inside the header/page.

Also, you need to use your theme's directory ... which will be along the lines of mydomain.com/wp-content/themes/BLANK-Theme/js/SliderViewer-1.2.js.

Use this code in functions.php:

function my_scripts_enqueue_method() {
    wp_enqueue_script(
        'SliderViewer',
        get_template_directory_uri() . '/js/SliderViewer-1.2.js'
    );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue_method' );

This will enqueue and register your script, and ensure that you're using the appropriate directory for your theme in the process.

share|improve this answer
    
I'm just trying to do this for ONE page though. –  Jackson Apr 9 '12 at 21:30
1  
For one page, then, you should really be using a custom page template. But the guidance on referencing the script in your call to wp_enqueue_script() stands. –  EAMann Apr 9 '12 at 21:33
    
This all works (accepted), but now I'm curious.. What was the problem with using wp_register_script? I like to be enlightened. –  Jackson Apr 9 '12 at 21:37
1  
No problem, just unnecessary. wp_enqueue_script() will automatically register the script for you. The biggest change was using get_template_directory_uri() to build the path to your script. –  EAMann Apr 9 '12 at 21:39
    
but you register with this snippet on all pages, backend and frontend. Use Conditional Tags, like is_admin() and is_singular() to load only on page, there you will use this script. –  bueltge Apr 10 '12 at 7:16
show 1 more comment

Your Answer

 
discard

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.