背景图片未保存在WordPress Customizer中 [英] Background image not saving in WordPress Customizer

查看:76
本文介绍了背景图片未保存在WordPress Customizer中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在WordPress定制程序中设置背景图片.我可以上传图像并在Customizer中查看它的预览,但是保存后,它不会出现在实时网站上.

I'm trying to set a background image in the WordPress Customizer. I can upload the image and see it preview in Customizer but after I save it, its not appearing on the live site.

在我的customter.php文件中有以下代码:

I have the following code in my customizer.php file:

$wp_customize->add_setting( 'section_1_background_image', array(
    'default'           => get_template_directory_uri() . '/images/default.jpg',
       'transport'      => 'postMessage',
) );    
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'section_1_background_image_control', array(
    'label'             => __('Background Image','minisite'),
    'settings'          => 'section_1_background_image',
    'section'           => 'section_1',
    'priority' => 10,
) ) );

以及我的customr.js文件中的相应代码

and the corresponding code in my customizer.js file

wp.customize( 'section_1_background_image', function( value ) {
    value.bind( function( newval ) {
        $('#wrapper-1').css('background-image', newval );
    } );
} );

此设置对于背景颜色也适用,但我认为它与"url"有关,需要在背景图像文件名前面的CSS中输出"url",而实际上并没有这样做.

This same setup works fine for background colors but I believe it has to do with "url" needing to be output in the css in front of the background-image filename, which it isn't doing.

我也尝试了以下失败的尝试:

I also tried the following with no success:

wp.customize( 'section_1_background_image', function( value ) {
    value.bind( function( newval ) {
        $('#wrapper-1').css('background-image', 'url("' + newval + '")' );
    } );
} );

我想念什么吗?

推荐答案

事实证明,在定制程序中显​​示它的正确代码是:

As it turns out, the correct code for displaying it in the Customizer was:

wp.customize( 'section_1_background_image', function( value ) {
    value.bind( function( newval ) {
        $('#wrapper-1').css('background-image', 'url("' + newval + '")' );
    } );
} ); 

但是,这不是将其正确保存在前端的问题.在此处即可解决.

However, this wasn't the problem for saving it properly on the front end. That was solved here.

这篇关于背景图片未保存在WordPress Customizer中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆