skip to Main Content

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


  1. Chosen as BEST ANSWER

    I managed to sort it out. I changed the html to a php include function and placed it at the bottom of my document:

    <script>
          <?php
            include '/home/fittecha/repositories/particles.js/particles.js';
            include '/home/fittecha/repositories/particles.js/particles.min.js';
            include '/home/fittecha/repositories/particles.js/demo/js/app.js';
    
          ?>
     </script>

    I am not sure why this didn't work before when I tried it but it's all working now


  2. There may be multiple reasons why it is not working :

    1. 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

    2. 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

    3. 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)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search