0

I am very new to build Wordpress Website, so please bear with me if I don't describe things properly.

There is a website providing the .js file for flying bats on the screen. https://www.delphitools.info/2013/10/30/pimp-your-website-with-an-halloween-bat/

It says that I can just insert the script by using

<script async src="https://cdn.delphitools.info/wp-content/uploads/2013/10/jsbat.js"></script>

but it doesn't work on the website.

What did I do wrong? Do I have to change something in the JS file?

Thank you in advance.

2
  • Where did you insert it? And did you follow the instructions and upload the file? Commented Oct 29, 2018 at 11:49
  • Thanks Jacob, I did download the file and use the plugin called "Header and Footer Script" to insert in Header by using <script async src="/wp-content/uploads/2018/10/jsbat.js"></script>. I do check the location on Media but it doesn't work. Commented Oct 29, 2018 at 11:54

1 Answer 1

0

Note: you should use child theme ( here I'll reference main theme )

I believe you've downloaded that jsbat.js file somewhere in your wordpress root directory consider this your root directory of web

/xampp/htdocs/wordpress_site/wp-content/themes/theme-name/assets/js/jsbat.js

now you'll need to find functions.php file in your theme. Typically this resides in this folder:

/xampp/htdocs/wordpress_site/wp-content/themes/theme-name/functions.php

edit functions.php file, and add following code:

add_action( 'wp_enqueue_scripts', 'fy_load_scripts' );
function fy_load_scripts(){
       wp_enqueue_script( 'jsbat-script-js', get_template_directory_uri(). '/assets/js/jsbat.js', array( 'jquery' ), '1.0.0', true );
}

this is just generalized answer, please modify ( you won't need to create function 'fy_load_scripts' but in case you don't know what to do just copy and paste the code in functions.php file and the directory structure should be matched as well )

Hope this helps Good luck!

6
  • I tried this in my localhost, it works but funny thing is I can only see one bat :) Commented Oct 29, 2018 at 12:04
  • Thank you Maverick. I am still trying it as I am really new to wordpress. :-) I did check where there are so many bats in that website. All we need to do is just duplicate the script to 3 or more, and we can see more bats on the screen. I did try it on my own test HTML. It worked in my <html><head><body> type of webpage. :-) Commented Oct 29, 2018 at 12:09
  • If your site is live, use child theme instead: this will give you a brief introduction to child theme and how to create them premium.wpmudev.org/blog/how-to-create-wordpress-child-theme Commented Oct 29, 2018 at 12:12
  • Hi Maverick, is the "/assets/js/jsbat.js" in the script code the location of where I keep the file I downloaded? Can I change it to /wp-content/uploads/2018/10/jsbat.js. does that make sense? Commented Oct 29, 2018 at 12:30
  • @Dan No need to upload via media upload as described by the script author. If you are calling your script correctly, then it will work fine. Just tested locally. Commented Oct 29, 2018 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.