WordPress登录注册页面 调用Bing每日一图

最近不知道写什么文章,所以今晚决定再水一篇wordpress简单技巧:调用Bing每日图片作为Wordpress注册登录页面背景图,实现每日自动更换。
其实这个网上有很多代码,但是我折腾的时候发现没找到完美的,譬如调用的图片像素不够、没有固定
于是自己调了一下
代码
方法其实非常简单,只需要在当前主题下的functions.php文件中,添加如下代码即可:

/**
* Bing每日一图
*/
function custom_login_head(){
$str=file_get_contents('https://global.bing.com/HPImageArchive.aspx?idx=0&n=1');
if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){
$imgurl='https://global.bing.com'.$matches[1];
echo'<style type="text/css">body{background: url('.$imgurl.');background-attachment:fixed;width:100%;height:100%;background-image:url('.$imgurl.');-moz-background-size: 100% 100%;-o-background-size: 100% 100%;-webkit-background-size: 100% 100%;background-size: 100% 100%;-moz-border-image: url('.$imgurl.') 0;background-repeat:no-repeat\9;background-image:none\9;}</style>';
}}
add_action('login_head', 'custom_login_head');

好了,就这么简单,又水了一篇。

为您推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注