1
votes

Im trying to get a custom header to my wordpress theme.

    $args = array(
    'width'         => 1920,
    'height'        => 800,
    'default-image' => get_template_directory_uri() . '/images/header.jpg',
    'uploads'       => true,
); add_theme_support( 'custom-header', $args );

Added that to my functions.php and want the default-image to be the image that show if its no image set in admin.

But it wont show anything. the "img src" is empty.

Tried to upload a image then it shows, what could be the problem?

<img src="<?php echo header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />

Using that in my front-page.php (the width and height is set correctly).

2

2 Answers

2
votes

I couldn't find anything wrong with your code. However you can try this below. It always works well for me.

<?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 } ?>
1
votes

Try:

<img src="<?php echo( get_header_image() ); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />