0

I've added the following code to functions.php of my activated child theme:

function fullpagejs() {
    $slimscroll = get_stylesheet_directory_uri() . '/library/fullPage.js-master/vendors/jquery.slimscroll.min.js' ;
    wp_register_script('fullpage-slimscroll', $slimscroll, false, null);
    //some more files will be added here later
}
add_action("wp_enqueue_scripts", "fullpagejs");

However when I check the page source, I can't find the script jquery.slimscroll.min.js registered.

2 Answers 2

0

You must not only register the script, but also enqueue it after that, like this:

wp_enqueue_script('fullpage-slimscroll');
6
  • Pleased to help you. Could you accept the answer by clicking on the "check" to the left. So everybody knows this question doesn't need attention anymore.
    – cjbj
    Commented May 17, 2016 at 14:01
  • Actually, there is no need to register the script before enqueueing.
    – Max Yudin
    Commented May 17, 2016 at 14:04
  • @Max Possibly, but there could also be reasons to do both: wordpress.stackexchange.com/questions/82490/…
    – cjbj
    Commented May 17, 2016 at 14:08
  • @MaxYudin according to WordPress, 'Registering scripts is technically not necessary, but highly recommended nonetheless.' so you're right, not needed but as the script has some dependencies (jquery) I will add it.
    – Luiza Rios
    Commented May 17, 2016 at 14:09
  • @cjbj sure, I'm a noobie so I wasnt sure how to signal the code worked. I've ticked it now :)
    – Luiza Rios
    Commented May 17, 2016 at 14:10
1

You are registering the script instead on enqueueing.

Also, slimScroll depends on jQuery. So you have to point it out explicitly.

function fullpagejs() {
    $slimscroll = get_stylesheet_directory_uri() . '/library/fullPage.js-master/vendors/jquery.slimscroll.min.js' ;
    wp_enqueue_script( // see here
        'fullpage-slimscroll',
        $slimscroll,
        array('jquery'), // dependency
        null
    );
    //some more files will be added here later
}
add_action("wp_enqueue_scripts", "fullpagejs");
5
  • You're right Max, I hadn't read your answer when I replied to the other one above. In fact, to make things harder, this scripts has another dependency which I also have to add to the website, so here's how the final code is looking:
    – Luiza Rios
    Commented May 17, 2016 at 14:22
  • code function fullpagejs() { wp_enqueue_script('jquery-ui', 'ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/…); $slimscroll = get_stylesheet_directory_uri() . '/library/fullPage.js-master/vendors/jquery.slimscroll.min.js' ; wp_register_script('fullpage-slimscroll', $slimscroll, array ('jquery', 'jquery-ui'), null); wp_enqueue_script('fullpage-slimscroll'); //some more files will be added here later } add_action("wp_enqueue_scripts", "fullpagejs");code
    – Luiza Rios
    Commented May 17, 2016 at 14:23
  • @LuizaRios If you want to use external libraries you have deregister native WP libraries first. jQuery and jQuery-UI are native. See the list here
    – Max Yudin
    Commented May 17, 2016 at 14:47
  • I don't want to use external libraries, I checked that list before but I couldn't find simple jquery-ui (although I did see dozens of jquery-ui-something) so I assumed this one had to be brought in manually, is that not the case? Can I just leave code array ('jquery', 'jquery-ui') code without first having to bring in the script?
    – Luiza Rios
    Commented May 17, 2016 at 14:59
  • @LuizaRios You had to look for jquery-ui-core in that list. array ('jquery', 'jquery-ui-core')
    – Max Yudin
    Commented May 17, 2016 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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