Can I Add a Start and End Time to the Event Title in Month View?

Home Forums Calendar Products Events Calendar PRO Can I Add a Start and End Time to the Event Title in Month View?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1143630
    David
    Participant

    I 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.

    #1143660
    Mathew
    Participant

    I 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.

    #1143695
    David
    Participant

    Mathew, 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!
    David

    #1143703
    Mathew
    Participant

    I 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 );

    #1143709
    David
    Participant

    That did it! Thanks again, for your help. I really appreciate it.

    #1143840
    Geoff
    Member

    Matthew, 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

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Can I Add a Start and End Time to the Event Title in Month View?’ is closed to new replies.