jlittlejohn
9/10/2014 - 4:46 PM

WP: Enqueue Styles, Scripts, & jQuery from CDN

WP: Enqueue Styles, Scripts, & jQuery from CDN

// enqueue stylesheets
function enqueue_styles() {
    // register fonts: http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic
    wp_register_style( 'fonts', 'http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic', array(), '', 'all' );  
    wp_enqueue_style( 'fonts' );
    // register main-style: styles.css 
    wp_register_style( 'main-style', get_template_directory_uri() . '/css/styles.css', array('fonts'), '', 'all' );  
    wp_enqueue_style( 'main-style' );
    // register animate: animate.min.css 
    wp_register_style( 'animate', get_template_directory_uri() . '/css/lib/animate.min.css', array('fonts', 'main-style'), '', 'all' );  
    wp_enqueue_style( 'animate' );
}  
add_action( 'wp_enqueue_scripts', 'enqueue_styles' );


// enqueue javascripts
function enqueue_scripts() {  
  // register main-script: main-min.js
  wp_register_script( 'main-script', get_template_directory_uri() . '/js/min/main-min.js', array( 'jquery' ), '', true );
  wp_enqueue_script( 'main-script' );  
}  
add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );


// enqueue jquery from google cdn
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
  wp_deregister_script('jquery');
  wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", false, null);
  wp_enqueue_script('jquery');
}