Featured Image not displaying in theme header

Home Forums Calendar Products Events Calendar PRO Featured Image not displaying in theme header

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #970035
    Gareth
    Participant

    Our theme uses featured images (when set) in the header as large banner images by calling “the_post_thumbnail” with custom sizes:

    if ( has_post_thumbnail() ) {
    	if ( is_mobile() ) {
    		the_post_thumbnail('headerpic_mobile');
    	} else {
    		the_post_thumbnail('headerpic');
    	}
    }

    But any Events Calendar featured images don’t display here. At the moment it only displays Events Calendar featured images in the events content section but this is below our header and navigation. This is the same with the default 2014 WP theme. Is this by design and is there a way round it?

    I’ve edited a copy of the single-event.php template to remove the featured image from there where we don’t want it to display.

    #970102
    George
    Participant

    Hey Gareth,

    I’m not sure why your theme wouldn’t pick up the featured image from events – the standard “thumbnail” is used for the events post type, not a funky or weird alternative, so in theory it should be picked up fine.

    We don’t offer support for troubleshooting themes, technically, but I’m curious about what you would find by replacing the above instances of this:

    
    the_post_thumbnail( 'headerpic_mobile' );
    

    With this:

    
    echo get_the_post_thumbnail( get_the_ID(), 'headerpic_mobile' );
    

    Use the ‘headerpic’ and ‘headerpic_mobile’ sizes where appropriate there, and try this out. Let us know what you find!

    Thanks,
    George

    #970181
    Gareth
    Participant

    Thanks for your reply George. Unfortunately that code didn’t make a difference. I wonder if it’s because the featured image is called in the header.php which is too far removed from the events loop. Normal pages and standard posts show their featured images as expected just not events unless the featured image is called in single-event.php.

    #970959
    Gareth
    Participant

    I did some hunting on displaying featured images outside the loop and managed to adapt some code into a working solution. Here’s my code snippet if it’s of help to anyone else:

    
    $thumbID = get_post_thumbnail_id( get_queried_object_id() );
    if ( has_post_thumbnail() ) { 
        the_post_thumbnail( $picsize );
    } else if($thumbID != '') {
        $bkgdImg = wp_get_attachment_image( $thumbID, $picsize );
        echo $bkgdImg;
    } else {
        [fallback]
    }
    
    #971634
    George
    Participant

    Thanks for sharing Gareth! Best of luck with your site.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Featured Image not displaying in theme header’ is closed to new replies.