I am trying to add javascript to the footer of a wordpress page using wp_enqueue_script in the functions file of a child theme.
I have never done this before so am a bit of a novice to using wp_enqueue_script but have read a fair few similar posts on the Stackoverflow forum but haven't found anything that resolves my issue, which is . . . the file source url is missing a "/" between the get_theme_file_uri()
part of the path and the remaining folderstructure.
I have inserted this code into the functions file:
function theme_enqueue_scripts() {
wp_enqueue_script( 'reactionform_js', get_stylesheet_directory_uri() . 'includes/js/reactionform_js.js');
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );
.
However, when i look at the source code on the rendered page the file path is <script type='text/javascript' src='https://www.futureproofpromotions.com/wp-content/themes/Avada-Child-Themeincludes/js/reactionform_js.js?ver=5.2.4'></script>
which is missing the / between the theme's root folder Avada-Child-Theme
& the includes
folder? FYI The error message on Chrome developer tools says: Failed to load resource: the server responded with a status of 404 (Not Found)
I have also tried get_theme_file_uri()
as opposed to get_stylesheet_directory_uri()
but no luck! I have also tried adding the forward slash (/) like this get_stylesheet_directory_uri() . '/'. 'includes/js/reactionform_js.js'
but also no luck.
I would appreciate if anyone could explain how to resolve this issue.
Also . . . as far as I understand, I believe I need to include , '' , '', true
after the $scr argument for the javascript to show in the footer instead of the header. However, at the moment when I include those arguments various parts of the page don't load, so have left those out until I at least get the script to load somewhere on the page. Once I have that, I'll add those arguments which hopefully will complete the task.
I am using: Wordpress: v 5.2.4 Avada Theme: v 6.1 php version 7.2.23 MySQL version: 5.5.62
Many thanks
Phil