1) {image_url} doesn’t work if you’ve removed the ‘medium’ size image format from your installation of WordPress, so that’s a possibility. Otherwise, it should be fine; but let me know if that’s not the issue.
2) You can create custom template tags easily using the My Calendar template API functions, so that you can get what you need. But the whole point of {link_image} is to present the image as a link, so it really needs to produce HTML. {image_url} should do what you’re looking for, although it does depend on the medium image size, specifically. (That also means that if you’re uploading a thumbnail size, it may not work, because WordPress doesn’t create upscaled images.)
1. I have the medium size in my thumbnails format. I am using the URL in a template as the following : <div class=”overlay-image” style=”background-image:url({image_url});”>
At rendering time the url is empty even though the event has an image
2. {image_url} is actually a workaround for me, because I requires me to assign an image to the event. Ideally I want to use the featured image of the linked post, but could not do this since {link_image} is returning a formatted anchor so doesn’t fit inside “background-image:url()”. Could you please elaborate or refer me to an article describing how I can achieve this using the My Calendar template API? Thanks.
So, {link_image} specifically returns an image with a link to the event details; it sounds like what you’re expecting is an image sourced *from* the associated linked post, which is never what that would return.
Use the filter ‘mc_filter_shortcodes’:
add_filter( 'mc_filter_shortcodes', 'my_function', 10, 2 );
function my_function( $e, $event ) {
$e['my_template_tag'] = 'My Template Tag Value';
return $e;
}
$e is the array of shortcodes, where the key is the shortcode and the value is what will be returned in templates; $event is the original event object, that you can use to source data.
Using the above code, you’d be able to call the template tag as {my_template_tag}.
Great! Thanks Joe. I could have what I wanted with the following code:
add_filter( 'mc_filter_shortcodes', 'mycal_link_image_url', 10, 2 );
function mycal_link_image_url( $e, $event ) {
$url = $e['linking'];
if (!empty($url)) {
$post_id = url_to_postid( $url );
if ( has_post_thumbnail( $post_id ) ) {
$image_url_array = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' );
$e['link_image_url'] = $image_url_array[0];
}
}
return $e;
}
If you could add this {link_image_url} to the next release that would be great, I am sure this would be useful to some.
Well, the whole point of having that API for adding new template tags is so that people can add whatever they need, without my generating absurd lists of tags — there are already a *lot* of tags available, and I could just go on forever…I’ll consider it, but I’m resistant to adding a lot of new template tags at this point.