Thanks Andrew. After much Googling and trial & error, I've come up with the following. I don't think it's a very elegant solution or even if the syntax is completely correct but it seems to work:
function custom_event($content) { global $post; if( get_field( "date" ) != "" || get_field( "time" ) != "" || get_field( "location" ) != "" ){ $open = "["; } if( get_field( "date" ) != ""){ $ondate = 'On '.get_field( "date" ); } if( get_field( "time" ) != ""){ $attime = 'at '.get_field( "time" ); } if( get_field( "location" ) != ""){ $atlocation = 'at '.get_field( "location" ); } if( get_field( "date" ) != "" || get_field( "time" ) != "" || get_field( "location" ) != "" ){ $close = "] "; } if( in_category( 'events', $post ) ) { $beforecontent = "<strong>$open$ondate $attime $atlocation$close</strong><br><br>"; $fullcontent = $beforecontent . $content; return $fullcontent; } return $content;}add_filter('the_content', 'custom_event');