<?php
/**
* Enqueue scripts and stylesheets
*
* Enqueue stylesheets in the following order:
* 1. /theme/assets/css/core.min.css
*
* Enqueue scripts in the following order:
* ---| jQuery |-----------------------------------------------------------------------------
* 1.1 jquery-1.11.3.min.js IE8 fallback via Google CDN
* 1.2 jquery-2.1.4.min.js via Google CDN
* CDN fallback:
* 1.3 jquery-1.11.3.min.js IE8 fallback to local if offline
* 1.4 jquery-2.1.4.min.js fallback to local if offline
* ------------------------------------------------------------------------------------------
* ---| Polyfills |--------------------------------------------------------------------------
* 2 /theme/assets/js/vendor/modernizr-2.8.3.min.js
* ------------------------------------------------------------------------------------------
* ---| Primary |----------------------------------------------------------------------------
* 3 /theme/assets/js/functions.min.js (in footer)
* ------------------------------------------------------------------------------------------
*/
function core_scripts () {
// Enquere stylesheets
wp_enqueue_style('core_css' get_template_directory_uri() . '/assets/css/core.min.css', false, '0');
// Grab latest jQuery from Google CDN's with a protocol relative URL; fallback to local if offline
if (!is_admin() && current_theme_supports('jquery-cdn')) {
wp_deregister_script('jquery');
// Google CDN fallback if lte IE 8
if (preg_match('/(?i)msie [6-8]/',$_SERVER['HTTP_USER_AGENT'])){
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', false, null, false);
}
else (){
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', false, null, false);
}
add_filter('script_loader_src', 'jquery_local_fallback', 10, 2);
}
if (is_single() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/vendor/modernizr-2.8.3.min.js', false, null, false);
wp_register_script('functions', get_template_directory_uri() . '/assets/js/functions.min.js', false, '0', true);
// Enquere scripts
wp_enqueue_script('jquery');
wp_enqueue_script('modernizr');
wp_enqueue_script('functions');
}
function jquery_local_fallback ($src, $handle) {
static $add_jquery_fallback = false;
if ($add_jquery_fallback) {
// Google CDN fallback for lte IE 8, local if offline
if (preg_match('/(?i)msie [6-8]/',$_SERVER['HTTP_USER_AGENT'])) {
echo '<script>window.jQuery || document.write(\'<script src="' . get_template_directory_uri() . '/assets/js/vendor/jquery-1.11.3.min.js"><\/script>\')</script>' . "\n";
$add_jquery_fallback = false;
}
else {
echo '<script>window.jQuery || document.write(\'<script src="' . get_template_directory_uri() . '/assets/js/vendor/jquery-2.1.4.min.js"><\/script>\')</script>' . "\n";
$add_jquery_fallback = false;
}
if ($handle === 'jquery') {
$add_jquery_fallback = true;
return $src;
}
}
function google_analytics() { ?>
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','<?php echo GOOGLE_ANALYTICS_ID; ?>');ga('send','pageview');
</script>
<?php }
if (GOOGLE_ANALYTICS_ID) {
add_action('wp_footer', 'google_analytics', 20);
}