Skip to content

Instantly share code, notes, and snippets.

@webaware
Created February 3, 2014 22:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webaware/8793362 to your computer and use it in GitHub Desktop.
Save webaware/8793362 to your computer and use it in GitHub Desktop.
Example of using custom thumbnails for Events Manager plugin for WordPress.
<?php
/*
Plugin Name: Events Manager custom thumbnails
Plugin URI: https://gist.github.com/webaware/8793362
Description: example of using custom thumbnails for events
Version: 1
Author: WebAware
Author URI: http://www.webaware.com.au/
@ref: http://snippets.webaware.com.au/snippets/stop-events-manager-from-cropping-thumbnails/
*/
add_filter('em_event_output_placeholder', 'events_manager_custom_thumbnails', 10, 3);
/**
* get event image as regular WordPress thumbnail
* (or any registered WordPress image size)
* @param string $result
* @param EM_Event $EM_Event
* @param string $placeholder
* @return string
*/
function events_manager_custom_thumbnails($result, $EM_Event, $placeholder) {
// check a custom image placeholder, pick up size
switch ($placeholder) {
case '#_CUSTOMEVENTIMAGETHUMB':
$size = 'thumb';
break;
case '#_CUSTOMEVENTIMAGEMEDIUM':
$size = 'medium';
break;
default:
$size = false;
}
// if size was set, get image of that size
if ($size) {
$imageID = get_post_thumbnail_id($EM_Event->post_id);
if ($imageID) {
$result = wp_get_attachment_image($imageID, $size);
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment