Skip to content

Instantly share code, notes, and snippets.

@bordoni
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save bordoni/b23ccd0fb5f3000ca753 to your computer and use it in GitHub Desktop.

Select an option

Save bordoni/b23ccd0fb5f3000ca753 to your computer and use it in GitHub Desktop.
Event Featured image defaults to venue Featured image then to a Defaults URL
<?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, 3 );
function tec_forum_938271( $featured_image, $post_id, $size ){
if ( ! empty( $featured_image ) ){
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment