Title::build_title( string $current_title = '', boolean $depth = true, null|string $sep = null )

Builds the page title from a context.

This method is a rewrite of the tribe_get_events_title function to make it leverage the local context, injectable and controllable, in place of the global one.


Parameters

$current_title

(string) (Optional) Current Title used on the page.

Default value: ''

$depth

(boolean) (Optional) Whether to display the taxonomy hierarchy as part of the title.

Default value: true

$sep

(null|string) (Optional) The separator sequence to separate the title components.

Default value: null


Top ↑

Return

(string) The page title.


Top ↑

Source

File: src/Tribe/Views/V2/Template/Title.php

	public function build_title( $depth = true ) {
		$context = $this->context ?: tribe_context();
		$posts   = $this->get_posts();

		if ( $context->is( 'featured' ) ) {
			$this->events_label_plural = sprintf(
				_x( 'Featured %s', 'featured events title', 'the-events-calendar' ),
				$this->events_label_plural
			);
		}

		if ( $context->is( 'single' ) && $context->is( 'event_post_type' ) ) {
			// For single events, the event title itself is required
			$title = get_the_title( $context->get( 'post_id' ) );
		} else {
			// For all other cases, start with 'upcoming events'
			$title = sprintf( esc_html__( 'Upcoming %s', 'the-events-calendar' ), $this->events_label_plural );
		}

		// If there's a date selected in the tribe bar, show the date range of the currently showing events
		$event_date = $context->get( 'event_date', false );

		$event_display_mode = $context->get( 'event_display_mode' );
		if ( $event_date && count( $posts ) ) {
			$title = $this->build_post_range_title( $context, $event_date );
		} elseif ( 'past' === $event_display_mode ) {
			$title = sprintf( esc_html__( 'Past %s', 'the-events-calendar' ), $this->events_label_plural );
		}

		if ( 'month' === $event_display_mode ) {
			$title = $this->build_month_title( $event_date );
		}

		if ( 'day' === $event_display_mode ) {
			$title = $this->build_day_title( $event_date );
		}

		$term = $context->get( TEC::TAXONOMY, false );
		if ( false !== $term && $depth ) {
			$cat = get_term_by( 'slug', $term, TEC::TAXONOMY );

			if ( $cat instanceof \WP_Term ) {
				$title = $this->build_category_title( $title, $cat );
			}
		}

		/**
		 * Allows for customization of the "Events" page title.
		 *
		 * This is the same filter used in the `tribe_get_events_title` function.
		 * This is by design, to allow the same filtering to apply. Since this method built the value using the context
		 * that is passed to filtering functions as a third parameter.
		 *
		 * @since 4.9.10
		 *
		 * @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.
		 * @param Context $context The context used to build the title, it could be the global one, or one externally
		 *                         set.
		 */
		$title = apply_filters( 'tribe_get_events_title', $title, $depth, $context );

		/**
		 * Filters the view title, specific to Views V2.
		 *
		 * While the `tribe_get_events_title` is called above this one for back-compatibility purposes, this filter
		 * is exclusive to the Views V2 implementation.
		 *
		 * @since 4.9.10
		 *
		 * @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.
		 * @param Context $context The context used to build the title, it could be the global one, or one externally
		 *                         set.
		 * @param array $posts An array of posts fetched by the View.
		 */
		return apply_filters( 'tribe_events_v2_view_title', $title, $depth, $context, $posts );
	}

Top ↑

Changelog

Changelog
Version Description
5.1.5 - Add filter for plural events label and move featured label to a method.
4.9.10 Introduced.