Default Photo

Home Forums Calendar Products Events Calendar PRO Default Photo

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #972405
    Jen Russo
    Participant

    Had this solution solved in another thread, here. This was with the previous TEC plugin 3.9 versions and now some images are being duplicated or some images have two images being displayed. The idea is to have an image be displayed as the feature image if the event does not have a feature image which will be taken from the venues image. If the venue or featured image does not have an image then a default logo image will displayed.

    Here is the code that was working with the TEC 3.9 version:

    <?php
    /*
     * If you already have something in your functions.php, please remove these first few lines
     */
    add_filter( 'tribe_event_featured_image', 'tec_forum_938271', 11, 4 );
    
    function tec_forum_938271( $featured_image, $post_id, $size, $image_src ){
    	if ( ! empty( $image_src ) ){
    		return $featured_image;
    	}
    
    	if ( ! tribe_is_event( $post_id ) ){
    		return $featured_image;
    	}
    
    	$event = get_post( $post_id );
    
    	$venue = get_post( tribe_get_venue_id( $event->ID ) );
    
    	$venue_featured = wp_get_attachment_image_src( get_post_thumbnail_id( $venue->ID ), $size );
    
    	if ( ! empty( $venue_featured ) ){
    		$image_url = $venue_featured[0];
    	} else {
    		// Default URL
    		$image_url = 'http://placehold.it/300x300';
    	}
    	$featured_image .= '<div class="tribe-events-event-image"><img src="' . $image_url . '" title="' . get_the_title( $event->ID ) . '" alt="' . get_the_title( $event->ID ) . '" /></div>';
    
    	return $featured_image;
    }
    #972540
    Barry
    Member

    Hi @mauitime,

    Try changing the line reading:

    if ( ! empty( $image_src ) ){

    To:

    if ( ! empty( $featured_image ) ){

    This is needed because a change in the actual filter hook means the $image_src variable is no longer available. Does that work for you?

    (Though you don’t have to, you could further tidy things up by removing $image_src from the list of arguments accepted by the function. I’ve asked Gustavo to update the snippet in question.)

    #985028
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Default Photo’ is closed to new replies.