Snippet: Add custom javascript file

Add following snippet to “functions.php”


add_action( 'wp_enqueue_scripts', 'mysite_enqueue' );
function mysite_enqueue() {
  wp_enqueue_script( 'mysite-scripts', get_stylesheet_directory_uri()."/js/mysite-scripts.js" );


By default this snippet will insert the javascript within the tags. It is always recommended to include the javascript in footer to increase the page load  time. Please see set 5th parameter to “true” to make the javascript load in footer. See full details here.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>