Php 再次在wordpress中添加自定义背景图像
我为我的wordpress主题启用了如下自定义背景:Php 再次在wordpress中添加自定义背景图像,php,css,wordpress,wordpress-theming,background-image,Php,Css,Wordpress,Wordpress Theming,Background Image,我为我的wordpress主题启用了如下自定义背景: add_theme_support('custom-background', array( 'default-color' => 'FFF', 'default-image' => get_template_directory_uri() . '/img/bg.jpg' )); 然后我抓取主体的类“.custom background”,因为我想更改背景大小: body.custom-background {
add_theme_support('custom-background', array(
'default-color' => 'FFF',
'default-image' => get_template_directory_uri() . '/img/bg.jpg'
));
然后我抓取主体的类“.custom background”,因为我想更改背景大小:
body.custom-background {
background-attachment: fixed!important;
background-position: center center!important;
background-repeat: no-repeat!important;
background-size: cover!important;
top: 0;
right: 0;
bottom: 0;
left: 0;
position: absolute;
}
我之所以将其定位为绝对的唯一原因是,因为我想添加一个具有相同背景属性但宽度为1000px且居中边距(0自动)的其他背景,以使用css过滤器模糊此部分:
body.custom-background:before {
content: "";
background-image: url(""); //here he should takes the custom background-image (of body.custom-background)
background-attachment: fixed!important;
background-position: center center!important;
background-repeat: no-repeat!important;
background-size: cover!important;
height: 100%;
right: 0;
left: 0;
margin: 0 auto;
width: 1000px;
position: fixed;
z-index: -1;
filter: blur(10px);
}
但当然wp不知道哪幅是背景图像。。。那么,我该如何解决这个问题——他再次将自定义背景图像置于:before选择器
希望您理解我的意思。您可以在header.php中编写以下代码
<?php $background = set_url_scheme( get_background_image() ); ?>
<style>
body.custom-background:before {
content: "";
background-image: url("<?php print $background; ?>");
background-attachment: fixed!important;
background-position: center center!important;
background-repeat: no-repeat!important;
background-size: cover!important;
height: 100%;
right: 0;
left: 0;
margin: 0 auto;
width: 1000px;
position: fixed;
z-index: -1;
filter: blur(10px);
}
</style>
body.custom背景:在{
内容:“;
背景图片:url(“”);
背景附件:固定!重要;
背景位置:中-中!重要;
背景重复:不重复!重要;
背景尺寸:封面!重要;
身高:100%;
右:0;
左:0;
保证金:0自动;
宽度:1000px;
位置:固定;
z指数:-1;
过滤器:模糊(10px);
}
这会有用的