I am trying to use a JavaScript library (from GitHub) on my website but I can’t get it to work. It works when I set it up in VS code but not when I upload my code to cpanel (along with the required files). The website is a wordpress site so I just create page templates and link the templates to the specific pages. I have uploaded all of the code and files correctly and this is how I have tried to include them:
#particles-js{
position: relative;
z-index: 1;
background-color: #000;
min-height: 100vh;
min-width: 100vw;
}
<div id="particles-js"></div>
<script src="/home/fittecha/repositories/particles.js/particles.js"></script>
<script src="/home/fittecha/repositories/particles.js/particles.min.js"></script>
<script src="/home/fittecha/repositories/particles.js/demo/js/app.js"></script>
I also tried using <?php include '/home/fittecha/repositories/particles.js/demo/js/app.js'; ?>
etc, but that didn’t work either. Please advise.
2
Answers
I managed to sort it out. I changed the html to a php include function and placed it at the bottom of my document:
I am not sure why this didn't work before when I tried it but it's all working now
There may be multiple reasons why it is not working :
first of all, please check the actual location of those static files( js files) and add the relative path to that PHP file. if that did not work, please add full path, like https://www.yourwebsite.com/wpcontent/themes/themename/js/myjsfile.js
As you are using WordPress, the place where you store your js file should be wp-content/themes//js/ . please check this location and file
also please check if .htaccess is there or not. something .htaccess file change the behavior of a PHP file when it tried to add any static content. the .htaccess is mostly used for URL rewrite (for SEO friendly URLs)