默认图像显示为空白 - WordPress主题自定义API



我想让我的主题用户能够通过主题自定义 API 替换横幅。我已经让它工作了,但是,默认图像显示为空白,当我单击"查看页面源代码"时,我得到以下内容:

<img src=" " alt="banner" />

默认图像显示在 API 窗口内的预览中,但不显示在浏览器中。当我上传横幅以替换默认横幅的那一刻,它就可以完美运行。但我就是无法显示默认图像。我做错了什么吗?

这是我的函数.php:

// Start New Section for Images
$wp_customize->add_section('customtheme_images', array(
'title' => _('Images'),
'description' => 'Change Images'
));
$wp_customize->add_setting('banner_image', array(
'default' => 'http://mywebsite.com/banner.jpg',
));
$wp_customize->add_control( new WP_Customize_Image_Control ($wp_customize,   'banner_image', array(
'label' => _('Change Banner'),
'section' => 'customtheme_images',
'settings' => 'banner_image'
) )); 

而且,这在我的标题中.php:

<img src="<?php echo get_theme_mod('banner_image'); ?>" alt="banner">
是的,

我已经检查了默认图像的路径,它是相关的。请帮忙!

使用$wp_customize->add_setting('banner_image', array( 'default' => 'http://mywebsite.com/banner.jpg', ));时,默认值不会保存到数据库中(直到保存)。

所以你将不得不使用:<img src="<?php echo get_theme_mod('banner_image','http://mywebsite.com/banner.jpg'); ?>" alt="banner">

您描述的问题与以下方面有关:https://wordpress.stackexchange.com/questions/129479/alternatives-to-handle-customizer-settings

我在这里也有同样的情况。以下解决方案的问题:

<?php echo get_theme_mod('banner_image','http://mywebsite.com/banner.jpg'); ?>

我需要用户能够删除默认图像。此默认图像将仅用于主题的初始显示。所以我需要一个解决方案,在激活主题时,它已经保存在数据库中。

最新更新