wordpress常用代码汇总

wordpress-wordpress常用代码汇总-

WordPress实用代码分享

//七牛镜像存储
if ( !is_admin() ) {
add_action('wp_loaded','c7sky_ob_start');
function c7sky_ob_start() {
ob_start('c7sky_qiniu_cdn_replace');
}
function c7sky_qiniu_cdn_replace($html){
$local_host = 'www.ysboke.cn'; //博客域名
$qiniu_host = 'cdn.ysboke.cn'; //七牛域名
$cdn_exts = 'js|css|jpg|jpeg|png|woff|woff2'; //扩展名(使用|分隔)
$cdn_dirs = 'wp-content|wp-includes'; //目录(使用|分隔)
$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;
}
}
匿名

发表评论

匿名网友