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. /
It says that I can just insert the script by using
<script async src=".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.
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.
Share Improve this question asked Oct 29, 2018 at 11:42 DanDan 11 bronze badge 2- Where did you insert it? And did you follow the instructions and upload the file? – Jacob Peattie 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. – Dan Commented Oct 29, 2018 at 11:54
1 Answer
Reset to default 0Note: 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!