Skip to content

Instantly share code, notes, and snippets.

@heiybb
Created November 8, 2015 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heiybb/1cd816c4d4cfa618fd3e to your computer and use it in GitHub Desktop.
Save heiybb/1cd816c4d4cfa618fd3e to your computer and use it in GitHub Desktop.
/** 替换特色图片附件为七牛 **/
/** ?imageView2/1/q/85/format/WEBP 暂时取消对图像进行WEBP处理**/
function QiNiuCDN(){
function Rewrite_URI($html){
/* 前面是需要用到七牛的域名,后面是需要加速的文件类型,使用分隔符 | 隔开即可 */
$pattern ='/http:\/\/heiybb\.com\/wp-content([^"\']*?)\.(jpg|png|jpeg)/i';
/* 七牛CDN空间地址 */
if($is_chrome){
$replacement = 'https://dn-img-blog.qbox.me$1.$2?imageView2/1/q/85/format/WEBP';
}
else{
$replacement = 'https://dn-img-blog.qbox.me$1.$2';
}
$html = preg_replace($pattern, $replacement,$html);
return $html;
}
/* 如果为管理员则显示原始链接 */
if(!is_admin()){
ob_start("Rewrite_URI");
}
}
add_action('init', 'QiNiuCDN');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment