wordpress - How to provide a local fallback for Font Awesome if CDN fails? -
I am trying to develop a Wordpress theme and the CDN fails or I
< Code> if ($ CDN_IS_AVAILABLE) {wp_enqueue_style}('font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css ', wrong); } Else {wp_enqueue_style ('font-awesome', get_template_directory_uri (). '/css/font-awesome/css/font-awesome.min.css', false, '4.0.3'); }
Thanks.
How about this?
& lt ;? Php $ test_url = @fopen ('https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css','r'); If ($ test_url! == incorrect) {// use the CDN function load_external () (wp_enqueue_style ('font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font- Use the 'add_action' ('wp_enqueue_scripts', 'load_external');} Else {// local if the URL is not available function load_local () {wp_enqueue_style ('font-awesome', get_template_directory_uri () '/css/font-awesome/css/font-awesome.min.css', false, '4.0.3');} Add_action ('wp_enqueue_scripts', 'load_local');}? & Gt;
Additionally, you can add wp_enqueue_script to the function to do this with JP.
Comments
Post a Comment