我正试图为我的wordpress主题获取一个自定义标题。
$args = array(
'width' => 1920,
'height' => 800,
'default-image' => get_template_directory_uri() . '/images/header.jpg',
'uploads' => true,
); add_theme_support( 'custom-header', $args );
将其添加到我的functions.php中,并希望默认图像是在admin中未设置图像时显示的图像。
但它不会显示任何东西。"img src"为空。
试图上传一张图片,结果显示,可能是什么问题?
<img src="<?php echo header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
在我的front-page.php中使用它(宽度和高度设置正确)。
我没有发现您的代码有任何错误。不过你可以在下面试试。它对我来说总是很好。
<?php if (get_header_image()) { ?>
<img src="<?php header_image(); ?>" alt="<?php bloginfo('name'); ?>">
<?php } else { ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/header.jpg" alt="<?php bloginfo('name'); ?>">
<?php } ?>
尝试:
<img src="<?php echo( get_header_image() ); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />