theme development - Test CDN link from function.php or wp_enqueue_scriptstyle?

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 down

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

相关推荐

  • theme development - Test CDN link from function.php or wp_enqueue_scriptstyle?

    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 down

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信