• I am trying to use the featured image and header work similar to this but I cannot seem to get it to work. The image only covers the part of the div that has the text. The full image is not showing.

    Here is my code:

    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    	<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
    	$image = $image[0]; ?>
    	<?php else :
    	$image = get_bloginfo( 'stylesheet_directory') . '/images/default_cat_img.jpg'; ?>
    	<?php endif; ?>
    	<div class="featimg" style="background-image: url('<?php echo $image; ?>')" >
    		<h1 class="entry-title"><?php the_title(); ?></h1>
    	</div><!-- end #featimg -->
    
    css:
     .featimg {
        position: relative;
    }
    .single .featimg, .page .featimg, .home .featimg {
        position: relative;
        line-height: 0;
        text-align: center;
    }
    .featimg{
        height: 100%;
        width: 100%;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        background-size: cover !important;
        position: absolute;
    }

Viewing 1 replies (of 1 total)
  • It’s a little hard to tell exactly from just this, but you might want to add something like this as well.

    background-position: 50% 50%;

    If you have a link it might help to troubleshoot better?

Viewing 1 replies (of 1 total)

The topic ‘Featured image header’ is closed to new replies.