WordPress 主题大多数都自带有添加背景图功能,不过部分主题为了可能觉得添加一张大大的背景图会拖慢网页加载速度

https://snxa.com/wp-content/uploads/2020/07/1596021231-61598d4566750d2.png

方法一:直接修改 style.css 文件

这个方法很简单,只需要将以下代码添加到当前主题的 style.css文件即可。

  1. body {
  2.     background-imageurl(http://localhost/wordpress/wp-content/uploads/2017/11/timg.jpg);
  3.     background-positioncenter center;
  4.     background-size: cover;
  5.     background-repeatno-repeat;
  6.     background-attachmentfixed;
  7. }

记得修改代码中的图片为自己的图片地址,图片大小建议为大图片,比如1920X1080。这个方法直接适用于 Nana主题和 Blogs主题,其他主题也同样适用。

方法二:在后台显示『背景』按钮

确保当前主题的 body 标签中有 body_class() 函数,没有就按方法一的方法直接添加(Nana主题和 Blogs主题可忽略此步骤)

将以下代码添加到当前主题的 functions.php 文件当中

  1. //添加背景按钮
  2. add_theme_support( 'custom-background');

此时,在我们 WordPress 站点后台 >> 外观 >> 背景 >> 背景图像 >> 添加背景图,然后设置为填满屏幕并保存发布即可。

https://snxa.com/wp-content/uploads/2020/07/1596021228-d5be6d1aaf258ff.png


微信扫描下方的二维码阅读更多精彩内容

https://snxa.com/wp-content/plugins/rest-api-to-wechat/images/qrcode/qrcode-2130.png