Enqueue Scripts

This tutorial will show you how to load additional stylesheets and scripts using the wp_enqueue_style and wp_enqueue_script function.

  • Create a child theme if it doesn't exist yet (creating a child theme will prevent theme updates overwrite your work)
  • In the child theme functions.php, add the enqueue functions as you want
  • To enqueue a stylesheet, use wp_enqueue_style plus the handler name and file location (get_template_directory_uri in the sample code below will output the theme folder path)
  • To enqueue a Javascript, use wp_enqueue_script plus the handler name and file location
  • The example below will add script.js and custom.css from the child theme folder

<?php

add_action('wp_enqueue_scripts', 'themify_add_scripts');

function themify_add_scripts(){
	wp_enqueue_script( 'script-name', get_stylesheet_directory_uri() . '/script.js');
	wp_enqueue_style( 'style-name', get_stylesheet_directory_uri() . '/custom.css');
}

?>