How to properly add and access a JavaScript file in WordPress?

I intend to use a JavaScript library on my WP website and have uploaded the JS file via FTP to the following directory belonging to the currently activated theme Salient: /public_html/wp-content/themes/salient/js

Then, in order to load the JavaScript, I have added the following line in the “Header and Footer” settings (to be injected before the body closing tag):

<script type=”text/javascript” src=”https://www.mypage…/public_html/wp-content/themes/salient/js/javascriptfile.js”></script>

When I am then loading a page and when inspecting it using the Chrome console, there’s a 404 error for that JS file, although the file and the directory exist. As an alternative approach I also tried to add the script reference directly in HTML and even the page template, but with the same result.

Why do I keep getting the 404 error? Thanks for your help.

Read more here:: How to properly add and access a JavaScript file in WordPress?

Leave a Reply

Your email address will not be published. Required fields are marked *