0

I have built a child theme out from the original parent theme. Having on completion learnt that it is standard industry practice to build a child theme (preferably from the start.) I have managed to convert 99.9% of the theme over to a child successfully however for some reason I cannot move one solitary js file (main.js) to my child assets folder. Images, style sheets , fonts etc.. have all been transferred to the child theme successfully however If I transfer the main. js file my parallax scroll (test) does not work. I am forced to leave this file by itself in its original parent folder location in order for this feature to work. Not ideal.

Tried every conceivable combination of enqueue, register and wpb_adding_scripts() functions I could find and nothing seems to work. This file only seems to work when left in its parent theme folder why is that?

NB. main.js shows as loading on my view page source but Still fails to work when the file is in my child theme…

footer.php

enter image description here

Folder Structure

h Any help appreciated

Thanks

  • I would avoid using bloginfo unless absolutely necessary, the way it's being used here is only possible to keep backwards compat, modern WP code uses functions such as get_template_directory_uri(), and use the enquing system WP provides rather than hardcoding the script tags. You're also loading 2 different copies of jQuery at the same time – Tom J Nowell May 19 '18 at 20:03
0

On line 18 of your child theme's functions.php you are enqueuing main.js with get_template_directory_uri(). That function is returning the path to you're parent theme. Try replacing it with get_stylesheet_directory_uri(), which will return the path to your child theme's root directory.

I can't blame you for not realizing the difference though. The developer.wordpress.org entry for get_template_directory_uri() is pretty sparse on details. The codex.wordpress.org entry for get_template_directory is much clearer and the two functions are closely related (the former returns a url, the latter returns a filesystem path) so you can infer what one does from the other.

From the codex entry for get_template_directory:

Retrieves the absolute path (eg: /home/user/public_html/wp-content/themes/my_theme) to the directory of the current theme.

If a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory.


Also, in the future, please try to copy and paste the code into the questions body instead of screenshoting it; it makes it easier for us to copy, edit and answer :)

  • It's always helpful to scroll down to the user notes when the dev hubs description is sparse or missing – Tom J Nowell May 19 '18 at 20:05
  • Agreed, though more often than not the comment/notes on the developer. domain are just copy/pastes from the codex entries. The transition to developer domain has been less then speedy IMO but it is what it is, the WP docs are still great. – DaveLak May 19 '18 at 20:09

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.