Load Custom JS Scripts

To load a custom js script when, for instance page ID 434 is loaded place the following in theme functions.php:

// load our own validation script on page 434
add_action( 'wp_enqueue_scripts', 'babelscribe_load_scripts' );

function babelscribe_load_scripts()
{
// register your script location, dependencies and version
wp_register_script('action_script', get_stylesheet_directory_uri().'/js/actions.js', array('jquery'));
// enqueue the script
if (is_page(434)) { // only load if it is selected page
wp_enqueue_script('validate_script');
}
}

 

Leave a Comment