Created
July 8, 2015 13:56
-
-
Save tomfinitely/45cf4a39a54ace74f626 to your computer and use it in GitHub Desktop.
The Events Calendar Pro - Default Organizer Featured Images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* From http://wordpress.stackexchange.com/questions/174412/setting-featured-image-based-on-related-post | |
/** Define a default post thumbnail Genesis */ | |
function default_event_image_fallback($output, $args) { | |
global $post; | |
if( $output || $args['size'] == 'full' && get_post_type() == 'tribe-events' ) | |
return $output; | |
$post_id = tribe_get_organizer_id(); | |
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size ); | |
$thumbnail = $image_src[0]; | |
switch($args['format']) { | |
case 'html' : | |
return '<img src="'.$thumbnail.'" class="attachment-'. $args['size'] .'" alt="'. get_the_title($post_id) .'" />'; | |
break; | |
case 'url' : | |
return $thumbnail; | |
break; | |
default : | |
return $output; | |
break; | |
} | |
} | |
add_filter('genesis_get_image', 'default_event_image_fallback', 10, 2); | |
/** Define a default post thumbnail Events Calendar */ | |
function set_default_event_featured_img( $featured_image, $post_id, $size, $image_src ) { | |
if ( ! $featured_image ) { | |
$post_id = tribe_get_organizer_id(); | |
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size ); | |
$featured_image = ''; | |
//if link is not specifically excluded, then include <a> | |
if ( ! empty( $image_src ) && $link ) { | |
$featured_image .= '<div class="tribe-events-event-image"><a href="' . tribe_get_event_link() . '" title="' . get_the_title( $post_id ) . '"><img src="' . $image_src[0] . '" title="' . get_the_title( $post_id ) . '" /></a></div>'; | |
} elseif ( ! empty( $image_src ) ) { | |
$featured_image .= '<div class="tribe-events-event-image"><img src="' . $image_src[0] . '" title="' . get_the_title( $post_id ) . '" /></div>'; | |
} | |
return apply_filters( 'tribe_event_featured_image', $featured_image, $post_id, $size, $image_src ); | |
} | |
else { | |
return $featured_image; | |
} | |
} | |
add_filter( 'tribe_event_featured_image', 'set_default_event_featured_img', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment