getting a js file for one page

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

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

What’s the path of that? Thanks-

Related posts

Leave a Reply

1 comment

  1. 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.