How can I check if CDN link is alive from function.php file on wp_enqueue section?
E.g. I have jQuery CDN and I have downloaded jQuery on local.
How can I test before mount theme (WordPress site) is CDN alive, if it is not, enqueue my local file?
Maybe test headers from request and status code?
$ch = curl_init('.5.0.min.js');
curl_exec($ch);
if (!curl_errno($ch)) {
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
case 304:
case 200: # OK
wp_register_script ( 'latest-jquery', '.5.0.min.js' );
break;
default:
wp_register_script ( 'latest-jquery', get_template_directory_uri() . '/js/jquery-3.5.0.min.js.js' );
}
}
curl_close($ch);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744538157a4579554.html
评论列表(0条)