Home › Forums › Calendar Products › Events Calendar PRO › Can I Add a Start and End Time to the Event Title in Month View?
- This topic has 6 replies, 4 voices, and was last updated 9 years, 9 months ago by
David.
-
AuthorPosts
-
July 25, 2016 at 7:31 am #1143630
David
ParticipantI found this tutorial on adding the start time to event titles in month view: https://theeventscalendar.com/knowledgebase/add-start-time-to-event-title/
However, I need to add both the start AND end time to the event in month view. Is that possible? If so, how do I do that?
Thanks, in advance, for your help.
July 25, 2016 at 8:47 am #1143660Mathew
ParticipantI wanted to accomplish the same thing and came up with this based on the same article. Give it a try. I added a line break after the start/end time to make it a little cleaner looking. You can remove the break if you want.
function tribe_add_start_end_time_to_month_view ( $post_title, $post_id ) { if ( ! tribe_is_event($post_id) ) return $post_title; // Checks if it is the month view, modify this line to apply to more views if ( ! tribe_is_month() ) return $post_title; $event_start_time = tribe_get_start_time( $post_id ); $event_end_time = tribe_get_end_time( $post_id ); if ( !empty( $event_start_time ) ) { $post_title = $event_start_time . ' - ' . $event_end_time . '<br/>' . $post_title; } return $post_title; } add_filter( 'the_title', 'tribe_add_start_end_time_to_month_view', 100, 2 );Hope this helps.
July 25, 2016 at 10:12 am #1143695David
ParticipantMathew, thank you so much for your help! The code you provided worked (though I had to remove “if ( ! tribe_is_event($post_id) ) return $post_title; {}” to keep the theme from breaking). The only small hiccup is that, after the start and end time, a <br/> tag is now being displayed. Any idea why? I have attached a screenshot so that you can see what I’m seeing.
Thanks again!
DavidJuly 25, 2016 at 10:19 am #1143703Mathew
ParticipantI think when I pasted the code, it made a mess of things. Not sure how to use the syntax highlighter on the forum.
function tribe_add_start_end_time_to_month_view ( $post_title, $post_id ) {if ( ! tribe_is_event($post_id) ) return $post_title;
// Checks if it is the month view, modify this line to apply to more views
if ( ! tribe_is_month() ) return $post_title;$event_start_time = tribe_get_start_time( $post_id );
$event_end_time = tribe_get_end_time( $post_id );if ( !empty( $event_start_time ) ) {
$post_title = $event_start_time . ' - ' . $event_end_time . '<br/>' . $post_title;
}
return $post_title;
}add_filter( 'the_title', 'tribe_add_start_end_time_to_month_view', 100, 2 );
July 25, 2016 at 10:24 am #1143709David
ParticipantThat did it! Thanks again, for your help. I really appreciate it.
July 25, 2016 at 2:46 pm #1143840Geoff
MemberMatthew, you did it again! Thanks so much for jumping in and helping.
David, I’ll go ahead and close this thread but do feel free to open a new one if any other questions pop up and we’d be happy to help — or maybe Matthew will. 🙂
Thanks!
Geoff -
AuthorPosts
- The topic ‘Can I Add a Start and End Time to the Event Title in Month View?’ is closed to new replies.
