The Proper Way to Add CSS and JS to a WordPress Theme June 23rd, 2014
Add this to functions.php for JS and CSS. Check out the WordPress Codex for available parameters and info on using the ‘$’ namespace for jQuery.
<?php
function wnt_styles(){
// STYLES
wp_register_style('bootstrapcss', get_template_directory_uri() . '/css/bootstrap.css', array(), '20140529', 'all' );
wp_enqueue_style('bootstrapcss');
}
add_action('wp_enqueue_scripts', 'wnt_styles');
wp_enqueue_script('jquery'); // This is all that's needed for jQuery since WordPress already has it registered as one of the core libraries
function wnt_scripts(){
// Register the script like this for a theme:
wp_register_script('wp-test-inclusion', get_template_directory_uri() . '/js/wp.test.inclusion.js', array('jquery'));
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script('wp-test-inclusion');
}
add_action('wp_enqueue_scripts', 'wnt_scripts');
?>