It would be nice if the feed settings included a default featured image. Is there any way to do this?
Thanks!
Susan
Susan Giles
Hi Susan,
This hasn’t really been a much requested featured, but there’s a couple of ways you can do this.
You an use the actions eventorganiser_ical_sync_event_inserted
/eventorganiser_ical_sync_event_update
:
add_action( 'eventorganiser_ical_sync_event_inserted', 'my_assign_thumbnail', 10, 3 );
function my_assign_thumbnail( $event_id, $event_array, $feed_id ){
//Check if event has thumbnail
//Assign thumbnail based on $feed_it if not.
}
My preferred way, is the ‘just in time’ method. That is, when displaying the event thumbnail, if it doesn’t have one, use a default image.
add_filter( 'post_thumbnail_html', 'my_post_thumbnail_html', 10, 2 );
function my_post_thumbnail_html( $html, $post_id ) {
if( 'event' != get_post_type( $post_id ) ){
return $html;
}
if ( empty( $html ) ){
//Optionally set default image url (e.g. image in [theme-directory]/images/default-images.png
//You can change this based on $feed_id:
$feed_id = get_post_meta( $post_id, '_eventorganiser_feed', true );
$html = '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.png' . '" alt="" />';
}
return $html;
}
Note that events are just posts and thumbnail handling is done entirely through WordPress’ thumbnail API. As such you can use all of WordPress’ thumbnail functions. Just not that Event ID ($event_id
) is the post ID.
Stephen Harris