Advertisement
BakerMan

Use event title in theme title (TEC 3.0)

Jul 25th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. add_filter('the_title', 'tribe_restore_title');
  2.  
  3. /**
  4.  * Tries to detect if the content is The Events Calendar related and returns the expected title. Useful where a theme
  5.  * displays the post/page title in a certain format before the event content is injected.
  6.  *
  7.  * Targets TEC 3.0.2. Notes: it looks on face value like better use could be made of tribe_is_event_query() and
  8.  * tribe_is_event() here, but because we're early in the request and want to avoid notices we'll avoid those.
  9.  *
  10.  * @param $title
  11.  * @return string
  12.  */
  13. function tribe_restore_title($title) {
  14.     global $wp_query;
  15.     global $post;
  16.  
  17.     if (-9999 !== $post->ID) return $title;
  18.     if ( ! isset($wp_query->tribe_is_event) || ! $wp_query->tribe_is_event) return $title;
  19.     if ( ! is_a($wp_query->posts[0], 'WP_Post') || $wp_query->posts[0]->ID == $post->ID) return $title;
  20.  
  21.     if (is_singular()) return $wp_query->posts[0]->post_title;
  22.     else return tribe_get_events_title();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement