七牛CDN加速代码
function qiniu_cdn_replace($html){ $local_host = 'https://www.msbear.cn'; //博客域名 $qiniu_host = 'https://static.msbear.cn'; //七牛域名 $cdn_exts = 'js|css|png|jpg|jpeg|gif|ico|flv|tiff|bmp|mp3|wmv|wma|rmvb|rm|avi|txt|doc|docx|xls|xlsx|zip|rar|pdf|mp4'; //扩展名(使用|分隔) $cdn_dirs = 'usr|admin'; //目录(使用|分隔) $cdn_dirs = str_replace('-', '\-', $cdn_dirs); if ($cdn_dirs) { $regex = '/' . str_replace('/', '\/', $local_host) . '\/((' . $cdn_dirs . ')\/[^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/'; $html = preg_replace($regex, $qiniu_host . '/$1$4', $html); } else { $regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/'; $html = preg_replace($regex, $qiniu_host . '/$1$3', $html); } return $html; }
PS:以上代码是从别人那里扒的
使用方法
首先,将以上代码复制进主题文件夹内的functions.php 注意替换掉博客域名和七牛域名
然后,在主题文件夹内的header.php最顶上加入以下代码:
<?phpob_start("qiniu_cdn_replace");
?>
好了,大功告成