WordPress - 自定义 Header
Wordpress - Custom Header
我正在尝试为我的 wordpress 主题定制 header。
$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 并希望 default-image 成为在管理中未设置图像时显示的图像。
但它不会显示任何内容。 "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 中使用它(宽度和高度设置正确)。
尝试:
<img src="<?php echo( get_header_image() ); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
我没有发现您的代码有任何问题。但是你可以在下面试试这个。它总是适合我。
<?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 } ?>
我正在尝试为我的 wordpress 主题定制 header。
$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 并希望 default-image 成为在管理中未设置图像时显示的图像。
但它不会显示任何内容。 "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 中使用它(宽度和高度设置正确)。
尝试:
<img src="<?php echo( get_header_image() ); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
我没有发现您的代码有任何问题。但是你可以在下面试试这个。它总是适合我。
<?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 } ?>