/** * Actually modifies the global $post object's title property, setting it to an empty string. * * This is expected to be called late on during the wp_title action, but does not in fact alter the string * it is passed. * * @see TribeEventsTemplates::maybe_modify_global_post_title() * @param string $title * @return string */ public static function modify_global_post_title($title = '') { global $post; // Set the title to an empty string (but record the original) self::$original_post_title = $post->post_title; $post->post_title = apply_filters('tribe_set_global_post_title', ''); // Restore as soon as we're ready to display one of our own views add_action('tribe_pre_get_view', array(__CLASS__, 'restore_global_post_title')); // Now return the title unmodified return $title; }
/** * Fix issues where themes display the_title() before the main loop starts. * * With such 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 event itself). * * There's no bulletproof solution to this, but in special cases where this workaround is undesirable it can * in fact be turned off by adding the following to wp-config.php: * * define( 'TRIBE_MODIFY_GLOBAL_TITLE', false ); */ 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 has not been turned off if (!tribe_is_event_query() || defined('TRIBE_MODIFY_GLOBAL_TITLE') && !TRIBE_MODIFY_GLOBAL_TITLE) { return; } if (!isset($post) || !is_a($post, 'WP_Post')) { return; } // Set the title to an empty string (but record the original) self::$original_post_title = $post->post_title; $post->post_title = apply_filters('tribe_set_global_post_title', ''); // Restore as soon as we're ready to display one of our own views add_action('tribe_pre_get_view', array(__CLASS__, 'restore_global_post_title')); }