Thanks for the quick reply briansteeleca! I may be a little confused as there are so many different instructions on that page. Here’s the code that I want to include in WordPress (altered with “example.js” and “example.com”. Also, not sure if I need the first <script LANGUAGE…> line.):
<script LANGUAGE=”JavaScript” SRC=”include/example.js”></script>
<script Language=”JavaScript”>
function validateemail(sEmailAdd){
if (sEmailAdd == “”)
{
alert(“Please enter your email address and try again.”);
document.frmLogin.txtusername.focus();
return false;
}
else
{
return true;
//var sFeatures = “top=” + ((screen.height / 2) – 300) + “,left=” + ((screen.width / 2) – 400) + “,height=550,width=750,status=yes,toolbar=yes,location=yes,resizable=yes,directories=no,scrollbars=yes”;
//window.open(“https://www.example.com/timetrax/content/fmeTimeTrax.asp?Email=” + sEmailAdd,””,sFeatures);
}
}
function CheckFields(frm) {
if (frm.txtusername.value == “”) {
alert(“Please enter your email address and try again.”);
return false;
}
return true;
}
</script>
Should I use this method in my Child Theme? If so, do I create a new file in my child theme folder?:
Load a Script from a Child Theme without Dependencies
Register and enqueue the script in the same callback function with no dependencies, in the footer. See wp_register_script() for details. In this example, google_analytics_object.js is the Google Analytics tracking code (provided by Google) in a file.
<?php
add_action( ‘wp_enqueue_scripts’, ‘child_add_scripts’ );
/**
* Register and enqueue a script that does not depend on a JavaScript library.
*/
function child_add_scripts() {
wp_register_script(
‘google-analytics’,
get_stylesheet_directory_uri() . ‘/google_analytics_object.js’,
false,
‘1.0’,
true
);
wp_enqueue_script( ‘google-analytics’ );
}
Or maybe use this? Also, where would I put it for my child theme?:
Using a Hook
Scripts and styles from a single action hook
/**
* Proper way to enqueue scripts and styles
*/
function theme_name_scripts() {
wp_enqueue_style( ‘style-name’, get_stylesheet_uri() );
wp_enqueue_script( ‘script-name’, get_template_directory_uri() . ‘/js/example.js’, array(), ‘1.0.0’, true );
}
add_action( ‘wp_enqueue_scripts’, ‘theme_name_scripts’ );