【发布时间】:2018-03-27 01:40:57
【问题描述】:
我正在为我的 wordpress 网站使用 BeTheme。现在我想通过设置背景图像(仅适用于该页面)来更改可能页面的主体背景之一。
我尝试通过添加它来更改我的 style.css,因为我了解到这可以为我完成这项工作。
body.page-id-269 {
background-image: url("http://example.com/wp-content/uploads/2017/03/your-background-image.jpg")!important;
background-position: center center!important;
background-repeat: repeat!important;
}
如何设置特定页面主体的背景图像?(我使用的是 BeTheme 主题)
更新
正如下面的答案提到的,我尝试了这些更改,在我的 functions.php 中添加了
add_filter('body_class', 'change_body_classes');
function change_body_classes($classes) {
if( is_page( 'page-id-269' ) ) {
$classes[] = 'my-background-class';
return $classes;
}
}
在我的风格中,我添加了这个 .css,
.my-background-class{
background-image: url("http://example.com/wp-content/uploads/2017/03/your-background-image.jpg")!important;
background-position: center center!important;
background-repeat: repeat!important;
}
【问题讨论】:
-
您可以在所述页面中创建一个 JS 变量,然后编写一个
if语句来查找该变量并在返回 true 时更改background-image属性 -
更改 style.css 时发生了什么?身体有适当的等级吗?你确定你的浏览器缓存没有给你旧的 CSS 吗?
-
@janh:什么也没发生。是的,我删除了缓存,我添加的 css 部分在我的 style.css 中。
-
body-tag 怎么样,添加了哪些类?
标签: css wordpress wordpress-theming background-image