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…
h Any help appreciated
Thanks
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…
h Any help appreciated
Thanks
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.
bloginfo
unless absolutely necessary, the way it's being used here is only possible to keep backwards compat, modern WP code uses functions such asget_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 ♦ Commented May 19, 2018 at 20:03