0

this is the directoryI am trying to integrate an animation in my Wordpress home page, for this I am trying to load scripts from "skrollr" library, but my styles and scripts don't load.

this is the code I added is function.php in the child theme:

function add_scripts() {
   wp_enqueue_style( 'main', get_stylesheet_directory_uri() . '/images/main.css' );
   wp_enqueue_script( 'skrollr', get_template_directory_uri() . '/js/skrollr.min.js', '', '', false);
}
add_action ('wp_enqueue_scripts', 'add_scripts');

and these are the errors that I get from the console: enter image description here

5
  • replace get_template_directory_uri() with get_stylesheet_directory_uri() and add '/' before 'main.css' Aug 21 '17 at 11:18
  • thanks for your reply but still have these errors:
    – jane
    Aug 21 '17 at 11:26
  • can you post an image of your theme directory or can you show me via teamviewer? I want to help you to resolve this issue. Aug 21 '17 at 11:30
  • Yes sure I can share it with you via teamviewer
    – jane
    Aug 21 '17 at 12:27
  • knock me here sbbrhs@gmail.com when you available to share teamviewer Aug 22 '17 at 15:25
0

You are using a child theme here, it means that you should use get_stylesheet_directory_uri() to get the child theme's directory.

So, in your case, get_stylesheet_directory_uri() will return:

localhost:8888/wp-content/themes/x-child/

and get_template_directory_uri() will return:

localhost:8888/wp-content/themes/x/

Use this to build your paths. Also, pay attention that you need to include a forward slash before your style/script's name, since these functions do not provide a trailing slash:

wp_enqueue_style( 'main', get_template_directory_uri() . '/main.css' );

Which will return:

localhost:8888/wp-content/themes/x/main.css
2
  • Thanks for your reply, I corrected it but the errors still remain
    – jane
    Aug 21 '17 at 13:07
  • Then I doubt the problem is with your functions, if you have build the proper paths and it's still not working.
    – Jack Johansson
    Aug 21 '17 at 13:08
0

This should work

function add_scripts() {
   wp_enqueue_style( 'main', get_stylesheet_directory_uri() . '/css/images/main.css' );
   wp_enqueue_script( 'skrollr', get_stylesheet_directory_uri() . '/js/skrollr.min.js', '', '', false);
}
add_action ('wp_enqueue_scripts', 'add_scripts');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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