I want to include my own javascript code in the front page of a wordpress site. I have located it and have tried many ways online to add javascript code to it but either the console says it failed to load the resource or that the method I called is not defined when I try to use it in an "onload" attribute. I have looked for many articles online but they seem to be talking about how to use it in a specific post. I want this code for the front page only.
This is how I have included the javascript most recently in the header file:
<?php echo '<script type="text/javascript"';
echo 'src="virtue-child/aboutUs.js"></script>'; ?>
You can create custom script file in js folder of your theme and call in your theme function.php
Ex: your script file name ->customjquery.js
function custom_scripts() {
wp_enqueue_script( 'customjquery', get_template_directory_uri() . '/js/customjquery.js', array(), '0001', true );
}
add_action( 'wp_head', 'custom_scripts' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.