tribe_get_events_title( bool $depth = true )
Event Title
Contents
Return an event’s title with pseudo-breadcrumb if on a category
Parameters
- $depth
-
(bool) (Optional) include linked title
Default value: true
Return
(string) title
Source
File: src/functions/template-tags/loop.php
function tribe_get_events_title( $depth = true ) {
if ( ! $wp_query = tribe_get_global_query_object() ) {
return;
}
$events_label_plural = tribe_get_event_label_plural();
if ( $wp_query->get( 'featured' ) ) {
$events_label_plural = sprintf( _x( 'Featured %s', 'featured events title', 'the-events-calendar'), $events_label_plural );
}
$tribe_ecp = Tribe__Events__Main::instance();
if ( is_single() && tribe_is_event() ) {
// For single events, the event title itself is required
$title = get_the_title();
} else {
// For all other cases, start with 'upcoming events'
$title = sprintf( esc_html__( 'Upcoming %s', 'the-events-calendar' ), $events_label_plural );
}
// If there's a date selected in the tribe bar, show the date range of the currently showing events
if ( isset( $_REQUEST['tribe-bar-date'] ) && $wp_query->have_posts() ) {
$first_returned_date = tribe_get_start_date( $wp_query->posts[0], false, Tribe__Date_Utils::DBDATEFORMAT );
$first_event_date = tribe_get_start_date( $wp_query->posts[0], false );
$last_event_date = tribe_get_end_date( $wp_query->posts[ count( $wp_query->posts ) - 1 ], false );
// If we are on page 1 then we may wish to use the *selected* start date in place of the
// first returned event date
if ( 1 == $wp_query->get( 'paged' ) && $_REQUEST['tribe-bar-date'] < $first_returned_date ) {
$first_event_date = tribe_format_date( $_REQUEST['tribe-bar-date'], false );
}
$title = sprintf( __( '%1$s for %2$s - %3$s', 'the-events-calendar' ), $events_label_plural, $first_event_date, $last_event_date );
} elseif ( tribe_is_past() ) {
$title = sprintf( esc_html__( 'Past %s', 'the-events-calendar' ), $events_label_plural );
}
if ( tribe_is_month() ) {
$title = sprintf(
esc_html_x( '%1$s for %2$s', 'month view', 'the-events-calendar' ),
$events_label_plural,
date_i18n( tribe_get_date_option( 'monthAndYearFormat', 'F Y' ), strtotime( tribe_get_month_view_date() ) )
);
}
// day view title
if ( tribe_is_day() ) {
$title = sprintf(
esc_html_x( '%1$s for %2$s', 'day_view', 'the-events-calendar' ),
$events_label_plural,
date_i18n( tribe_get_date_format( true ), strtotime( $wp_query->get( 'start_date' ) ) )
);
}
if ( is_tax( $tribe_ecp->get_event_taxonomy() ) && $depth ) {
$cat = get_queried_object();
$title = '<a href="' . esc_url( tribe_get_events_link() ) . '">' . $title . '</a>';
$title .= ' › ' . $cat->name;
}
/**
* Allows for customization of the "Events" page title.
*
* @param string $title The "Events" page title as it's been generated thus far.
* @param bool $depth Whether to include the linked title or not.
*/
return apply_filters( 'tribe_get_events_title', $title, $depth );
}