Skip to content

Instantly share code, notes, and snippets.

@jfeliweb
Created December 14, 2015 14:32
Show Gist options
  • Select an option

  • Save jfeliweb/88840cd195dedb4f4c98 to your computer and use it in GitHub Desktop.

Select an option

Save jfeliweb/88840cd195dedb4f4c98 to your computer and use it in GitHub Desktop.
Enqueue Script for WordPress
/* Proper way to enqueue scripts and styles */
function mytheme_custom_scripts(){
// Register and Enqueue a Stylesheet
// get_template_directory_uri will look up parent theme location
wp_register_style( 'name-of-style', get_template_directory_uri() . '/css/custom-style.css');
wp_enqueue_style( 'name-of-style' );
// Register and Enqueue a Script
// get_stylesheet_directory_uri will look up child theme location
wp_register_script( 'name-of-script', get_stylesheet_directory_uri() . '/js/custom-script.js', array('jquery'));
wp_enqueue_script( 'name-of-script' );
}
add_action('wp_enqueue_scripts', 'mytheme_custom_scripts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment