Last active
March 11, 2016 20:37
-
-
Save ethangardner/fef48abd4af738280957 to your computer and use it in GitHub Desktop.
Loading scripts in functions.php and removing from header.php (recommended)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* We've stripped the script tags from header.php and relocated them to functions.php | |
*/ | |
// loads the external scripts | |
function wptheme_load_scripts() { | |
wp_deregister_script( 'jquery' ); // deregisters the version of jQuery shipped with WP so you can use Google's CDN | |
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js' ); | |
wp_enqueue_script( 'jquery' ); // actually loads it on the page | |
wp_enqueue_script( 'wptheme-site', get_template_directory_uri() . '/js/modernizr.js', array(), '2' ); | |
wp_enqueue_script( 'wptheme-site', get_template_directory_uri() . '/js/script.js', array( 'jquery' ), '2' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'wptheme_load_scripts'); | |
// loads inline scripts at the very bottom when the wp_head() function is called in header.php | |
function wptheme_load_conditional_scripts() { | |
?> | |
<!--[if lte IE 8]> | |
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/html5shiv.min.js"></script> | |
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/respond.min.js"></script> | |
<![endif]--> | |
<?php | |
} | |
add_action( 'wp_head', 'wptheme_load_conditional_scripts', PHP_INT_MAX ); | |
/** | |
* Other functions go here | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html <?php language_attributes(); ?>> | |
<head> | |
<meta charset="<?php bloginfo( 'charset' ); ?>" /> | |
<title><?php wp_title( '|', true, 'right' ); ?></title> | |
<?php wp_head(); ?> | |
</head> | |
<?php | |
// Rest of the template would go here... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment