WordPress站点图片使用单独域名

今天给大家分享一篇图片加速优化教程,将站内的所有图片使用单独域名。然后再通过使用CDN加速该域名,使图片优化

我们在 wp-config.php中加入如下代码:

//指定cookies的域名
define('COOKIE_DOMAIN', 'www.ruikeedu.com');

然后在模板目录下的function.php添加以下内容

//更改站内图片域名
ob_start("Static_Switch");
function Static_Switch($buffer){
$buffer_out = preg_replace('/http:\/\/www.youdomin.com\.com\/wp-([^"\']*?)\.(jpg|png|gif|css|js|woff|woff2|ttf|svg|eot)/i','http://cdn.youdomin.com/wp-$1.$2',$buffer);
return $buffer_out;
}

如果使用了WP Super Cache 的插件的静态化功能一定要要清除一下缓存,最后再用这个域名使用CDN加速

转载请注明原文地址:半厘米Wordpress » WordPress站点图片使用单独域名
微信:半厘米Wordpress
搜集分享国内外海量精美Wordpress主题
12010人已关注
分享到:
赞(5) 打赏

评论2789

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #2789
    Needed to put you this little bit of word to help thank you the moment again relating to the incredible guidelines you've shared on this site. It was simply seriously generous of you to offer openly what a few people would have offered as an ebook to earn some bucks for their own end, and in particular since you could have tried it in case you decided. Those smart ideas additionally acted as a easy way to understand that other people online have the identical interest just as mine to find out a little more regarding this condition. I am certain there are thousands of more pleasant opportunities up front for folks who scan your blog.
    yeezy boost2019-01-17 10:55:21回复
  2. #2788
    I'm also writing to make you be aware of what a fine discovery our daughter found going through yuor web blog. She learned lots of details, most notably how it is like to possess an awesome helping spirit to have many more completely thoroughly grasp various grueling matters. You really exceeded readers' expectations. Thank you for churning out such warm and helpful, dependable, revealing and also fun guidance on your topic to Tanya.
    goyard wallet2019-01-17 19:57:11回复
  3. #2787
    I must show appreciation to this writer just for rescuing me from this particular issue. Because of checking through the the net and coming across ideas that were not helpful, I believed my entire life was well over. Existing devoid of the solutions to the difficulties you've fixed through your short article is a critical case, and the ones which may have adversely affected my career if I had not noticed your site. Your primary competence and kindness in touching all the pieces was important. I'm not sure what I would've done if I hadn't come across such a stuff like this. It's possible to at this point look forward to my future. Thanks so much for this impressive and sensible guide. I won't be reluctant to suggest your web page to any person who would need direction on this topic.
    kate spade handbags2019-01-18 5:21:58回复
  4. #2786
    I wish to express some thanks to you for rescuing me from this particular situation. As a result of surfing around throughout the the web and obtaining principles which were not productive, I was thinking my life was over. Existing without the solutions to the difficulties you've fixed as a result of your good site is a serious case, as well as ones that could have adversely damaged my entire career if I hadn't encountered your blog. Your own personal competence and kindness in dealing with every part was very useful. I'm not sure what I would have done if I hadn't discovered such a stuff like this. I can at this moment relish my future. Thank you so much for this impressive and sensible help. I won't be reluctant to refer your web site to any individual who needs and wants recommendations about this matter.
    hermes birkin2019-01-18 12:23:46回复
  5. #2785
    My spouse and i ended up being absolutely fulfilled when Jordan could finish off his research by way of the ideas he grabbed from your blog. It is now and again perplexing to simply find yourself making a gift of procedures which many people could have been trying to sell. And we all fully understand we now have the writer to thank because of that. The most important explanations you've made, the straightforward site navigation, the friendships you can assist to create - it's got everything sensational, and it is aiding our son in addition to the family reckon that this matter is satisfying, and that is very pressing. Thanks for all!
    adidas nmd r12019-01-18 18:18:16回复
  6. #2784
    I precisely needed to thank you so much again. I'm not certain what I could possibly have gone through in the absence of the entire ideas shown by you directly on such a topic. It had been a very frightening setting for me personally, nevertheless finding out your professional way you resolved it took me to cry for fulfillment. I will be grateful for the support and trust you comprehend what an amazing job you are always providing teaching people today through the use of your website. I am certain you've never met all of us.
    golden goose sneakers2019-01-18 20:59:32回复
  7. #2783
    My spouse and i felt very excited when Michael could complete his inquiry while using the precious recommendations he discovered while using the web pages. It is now and again perplexing to simply be giving out techniques that many other folks have been trying to sell. And now we do know we have got the website owner to be grateful to for this. The main explanations you have made, the straightforward site menu, the relationships your site make it easier to foster - it's mostly amazing, and it's letting our son and us understand that subject is enjoyable, and that is tremendously essential. Thanks for the whole thing!
    bape hoodie2019-01-19 5:33:29回复
  8. #2782
    Thank you for each of your effort on this website. My mum enjoys carrying out investigation and it's really easy to see why. Many of us notice all of the dynamic medium you offer sensible guides by means of this web site and increase participation from some others on that subject while our favorite princess is learning a lot. Have fun with the remaining portion of the new year. Your performing a first class job.
    kyrie irving shoes2019-01-19 12:48:33回复
  9. #2781
    Thank you for all of your work on this site. Gloria take interest in going through investigation and it is simple to grasp why. My partner and i hear all about the powerful form you produce simple guidelines through this web site and in addition foster participation from other ones on the matter plus my child is without a doubt starting to learn a lot. Take pleasure in the rest of the new year. You are always performing a dazzling job.
    pure boost2019-01-19 22:28:31回复
1 277 278 279
切换注册

登录

忘记密码 ?

切换登录

注册