Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wp_enqueue_script( 'bootstrap', 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js', array('jquery'), 3.3, true);
- $get_the_url = 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js';
- $cdnIsUp = get_transient( 'cnd_is_up' );
- if ( $cdnIsUp ) {
- $load_source = 'load_external_bootstrap';
- } else {
- $cdn_response = wp_remote_get( $get_the_url );
- if( is_wp_error( $cdn_response ) || wp_remote_retrieve_response_code($cdn_response) != '200' ) {
- $load_source = 'load_local_bootstrap';
- }
- else {
- $cdnIsUp = set_transient( 'cnd_is_up', true, MINUTE_IN_SECONDS * 20 );
- $load_source = 'load_external_bootstrap';
- }
- }
- add_action('wp_enqueue_scripts', $load_source );
- function load_external_bootstrap() {
- wp_register_script( 'bootstrap', 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js', array('jquery'), 3.3, true);
- wp_enqueue_script('bootstrap');
- }
- function load_local_bootstrap() {
- wp_register_script('bootstrap', get_bloginfo('template_url').'/js/bootstrap.min.js', __FILE__, array('jquery'), 3.3, true);
- wp_enqueue_script('bootstrap');
- }
- requirejs.config({
- enforceDefine: true,
- paths: {
- jquery: [
- '//ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min',
- //If the CDN location fails, load from this location
- //xyz.com/jquery.min.js
- ]
- }
- });
- $get_the_url = 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js';
- $test_the_url = @fopen( $get_the_url,'r' );
- if ( $test_the_url !== false ) {
- function load_external_bootstrap() {
- wp_register_script( 'bootstrap', 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js', array('jquery'), 3.3, true);
- wp_enqueue_script('bootstrap');
- }
- add_action('wp_enqueue_scripts', 'load_external_bootstrap');
- } else {
- function load_local_bootstrap() {
- wp_register_script('bootstrap', get_bloginfo('template_url').'/js/bootstrap.min.js', __FILE__, array('jquery'), 3.3, true);
- wp_enqueue_script('bootstrap');
- }
- add_action('wp_enqueue_scripts', 'load_local_bootstrap');
- }
- function wp_enqueue_cdn_script( $handle, $src_cdn = false, $src_local = false, $deps = array(), $ver = false, $in_footer = false ) {
- $cdnIsUp = get_transient( $handle . '_script_cdn_is_up' );
- if ( $cdnIsUp ) {
- wp_enqueue_script( $handle, $src_cdn, $deps, $ver, $in_footer );
- } else {
- $cdn_response = wp_remote_get( $src_cdn );
- if ( is_wp_error( $cdn_response ) || wp_remote_retrieve_response_code( $cdn_response ) != '200' ) {
- wp_enqueue_script( $handle, $src_local, $deps, $ver, $in_footer );
- } else {
- $cdnIsUp = set_transient( $handle . '_script_cdn_is_up', true, MINUTE_IN_SECONDS * 20 );
- wp_enqueue_script( $handle, $src_cdn, $deps, $ver, $in_footer );
- }
- }
- }
- function wp_enqueue_cdn_style( $handle, $src_cdn = false, $src_local = false, $deps = array(), $ver = false, $media = 'all' ) {
- $cdnIsUp = get_transient( $handle . '_style_cdn_is_up' );
- if ( $cdnIsUp ) {
- wp_enqueue_style( $handle, $src_cdn, $deps, $ver, $media);
- } else {
- $cdn_response = wp_remote_get( $src_cdn );
- if ( is_wp_error( $cdn_response ) || wp_remote_retrieve_response_code( $cdn_response ) != '200' ) {
- wp_enqueue_style( $handle, $src_local, $deps, $ver, $media);
- } else {
- $cdnIsUp = set_transient( $handle . '_style_cdn_is_up', true, MINUTE_IN_SECONDS * 20 );
- wp_enqueue_style( $handle, $src_cdn, $deps, $ver, $media);
- }
- }
- }
- function theme_styles()
- {
- wp_enqueue_style( 'bootstrap_css', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
- }
- add_action( 'wp_enqueue_scripts', 'theme_styles');
- global $wp_scripts;
- wp_enqueue_script( 'bootstrap_js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js');
- }
- add_action( 'wp_enqueue_scripts', 'theme_js');
Add Comment
Please, Sign In to add comment