上载到定制器的图像未显示

时间:2020-07-20 作者:user2565143

我在自定义程序中添加了一个部分,用于上载主站点的背景图像。我在这里称之为:

.header_wrapper{
background:url(\'<?php echo get_theme_mod( \'header_image_uploaded\', \'http://www.unitedwayofmilford.org/wp-content/uploads/2020/03/Canva-Lending-a-helping-hand..jpg\' ); ?>\') no-repeat center center fixed;
它没有出现。

以下是我的自定义程序功能的代码

function uwm_customize_register( $wp_customize ) {

$wp_customize->add_setting( \'header_image\' , array(
\'default\'   => \'http://www.unitedwayofmilford.org/wp-content/uploads/2020/03/Canva-Lending-a-helping-hand.jpg\',) );

$wp_customize->add_section( \'main_header_image\' , array(
\'title\'      => __( \'Choose Your Main Image\', \'uwm\' ),) );

$wp_customize->add_control( 
new WP_Customize_Upload_Control( 
$wp_customize, 
\'header_image_uploaded\', 
array(
    \'label\'      => __( \'Main Image Upload\', \'uwm\' ),
    \'section\'    => \'main_header_image\',
    \'settings\'   => \'header_image\',) ) );
}add_action( \'customize_register\', \'uwm_customize_register\' );
任何帮助都将不胜感激。

1 个回复
SO网友:Jacob Peattie

该字段的值将是上载附件的ID。不是图像URL。您需要使用wp_get_attachment_image_url() 获取URL。

echo wp_get_attachment_image_url( get_theme_mod( \'header_image_uploaded\' ), \'full\' );

相关推荐