$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Can I just insert JavaScript by using <script>?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Can I just insert JavaScript by using <script>?

matteradmin8PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 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!

Post a comment

comment list (0)

  1. No comments so far