Tribe__Events__Templates::maybe_modify_global_post_title()

Fix issues where themes display the_title() before the main loop starts.

Contents

With some themes the title of single events can be displayed twice and, more crucially, it may result in the event views such as month view prominently displaying the title of the most recent event post (which may not even be included in the view output).

There’s no bulletproof solution to this problem, but for affected themes a preventative measure can be turned on by adding the following to wp-config.php:

define( 'TRIBE_MODIFY_GLOBAL_TITLE', true );

Note: this reverses the situation in version 3.2, when this behaviour was enabled by default. In response to feedback it will now be disabled by default and will need to be turned on by adding the above line.

See also


Top ↑

Source

File: src/Tribe/Templates.php

		public static function maybe_modify_global_post_title() {
			global $post;

			// We will only interfere with event queries, where a post is set and this behaviour is enabled
			if ( ! tribe_is_event_query() || ! defined( 'TRIBE_MODIFY_GLOBAL_TITLE' ) || ! TRIBE_MODIFY_GLOBAL_TITLE ) {
				return;
			}
			if ( ! isset( $post ) || ! $post instanceof WP_Post ) {
				return;
			}

			// Wait until late in the wp_title|document_title_parts hook to actually make a change - this should allow single event titles
			// to be used within the title element itself
			add_filter( 'document_title_parts', array( __CLASS__, 'modify_global_post_title' ), 1000 );
			add_filter( 'wp_title', array( __CLASS__, 'modify_global_post_title' ), 1000 );
		}