bbp_title

Custom page title for bbPress pages.

Description

(string) bbp_title( (string) $title = '', (string) $sep = '»', (string) $seplocation = '' ); 

Returns (string)

The tite

Parameters (3)

0. $title — Optional. (string) => ''
The title (not used).
1. $sep — Optional. (string) => '»'
Optional, default is ».. How to separate the various items within the page title.
2. $seplocation — Optional. (string) => ''
Direction to display title, right..

Usage

  1. if ( !function_exists( 'bbp_title' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/template.php'; 
  3.  
  4. // Optional. The title (not used). 
  5. $title = ''; 
  6.  
  7. // Optional, default is '»'. How to separate the 
  8. // various items within the page title. 
  9. $sep = '»'; 
  10.  
  11. // Optional. Direction to display title, 'right'. 
  12. $seplocation = ''; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = bbp_title($title, $sep, $seplocation); 
  16.  

Defined (1)

The function is defined in the following location(s).

/includes/common/template.php  
  1. function bbp_title( $title = '', $sep = '»', $seplocation = '' ) { 
  2.  
  3. // Title array 
  4. $new_title = array(); 
  5.  
  6. /** Archives **************************************************************/ 
  7.  
  8. // Forum Archive 
  9. if ( bbp_is_forum_archive() ) { 
  10. $new_title['text'] = bbp_get_forum_archive_title(); 
  11.  
  12. // Topic Archive 
  13. } elseif ( bbp_is_topic_archive() ) { 
  14. $new_title['text'] = bbp_get_topic_archive_title(); 
  15.  
  16. /** Edit ******************************************************************/ 
  17.  
  18. // Forum edit page 
  19. } elseif ( bbp_is_forum_edit() ) { 
  20. $new_title['text'] = bbp_get_forum_title(); 
  21. $new_title['format'] = esc_attr__( 'Forum Edit: %s', bbpress ); 
  22.  
  23. // Topic edit page 
  24. } elseif ( bbp_is_topic_edit() ) { 
  25. $new_title['text'] = bbp_get_topic_title(); 
  26. $new_title['format'] = esc_attr__( 'Topic Edit: %s', bbpress ); 
  27.  
  28. // Reply edit page 
  29. } elseif ( bbp_is_reply_edit() ) { 
  30. $new_title['text'] = bbp_get_reply_title(); 
  31. $new_title['format'] = esc_attr__( 'Reply Edit: %s', bbpress ); 
  32.  
  33. // Topic tag edit page 
  34. } elseif ( bbp_is_topic_tag_edit() ) { 
  35. $new_title['text'] = bbp_get_topic_tag_name(); 
  36. $new_title['format'] = esc_attr__( 'Topic Tag Edit: %s', bbpress ); 
  37.  
  38. /** Singles ***************************************************************/ 
  39.  
  40. // Forum page 
  41. } elseif ( bbp_is_single_forum() ) { 
  42. $new_title['text'] = bbp_get_forum_title(); 
  43. $new_title['format'] = esc_attr__( 'Forum: %s', bbpress ); 
  44.  
  45. // Topic page 
  46. } elseif ( bbp_is_single_topic() ) { 
  47. $new_title['text'] = bbp_get_topic_title(); 
  48. $new_title['format'] = esc_attr__( 'Topic: %s', bbpress ); 
  49.  
  50. // Replies 
  51. } elseif ( bbp_is_single_reply() ) { 
  52. $new_title['text'] = bbp_get_reply_title(); 
  53.  
  54. // Topic tag page 
  55. } elseif ( bbp_is_topic_tag() || get_query_var( 'bbp_topic_tag' ) ) { 
  56. $new_title['text'] = bbp_get_topic_tag_name(); 
  57. $new_title['format'] = esc_attr__( 'Topic Tag: %s', bbpress ); 
  58.  
  59. /** Users *****************************************************************/ 
  60.  
  61. // Profile page 
  62. } elseif ( bbp_is_single_user() ) { 
  63.  
  64. // User is viewing their own profile 
  65. if ( bbp_is_user_home() ) { 
  66. $new_title['text'] = esc_attr_x( 'Your', 'User viewing his/her own profile', bbpress ); 
  67.  
  68. // User is viewing someone else's profile (so use their display name) 
  69. } else { 
  70. $new_title['text'] = sprintf( esc_attr_x( "%s's", 'User viewing another users profile', bbpress ), get_userdata( bbp_get_user_id() )->display_name ); 
  71.  
  72. // User topics created 
  73. $new_title['format'] = esc_attr__( "%s Topics", bbpress ); 
  74.  
  75. // User rueplies created 
  76. } elseif ( bbp_is_single_user_replies() ) { 
  77. $new_title['format'] = esc_attr__( "%s Replies", bbpress ); 
  78.  
  79. // User favorites 
  80. } elseif ( bbp_is_favorites() ) { 
  81. $new_title['format'] = esc_attr__( "%s Favorites", bbpress ); 
  82.  
  83. // User subscriptions 
  84. } elseif ( bbp_is_subscriptions() ) { 
  85. $new_title['format'] = esc_attr__( "%s Subscriptions", bbpress ); 
  86.  
  87. // User "home" 
  88. } else { 
  89. $new_title['format'] = esc_attr__( "%s Profile", bbpress ); 
  90.  
  91. // Profile edit page 
  92. } elseif ( bbp_is_single_user_edit() ) { 
  93.  
  94. // Current user 
  95. if ( bbp_is_user_home_edit() ) { 
  96. $new_title['text'] = esc_attr__( 'Edit Your Profile', bbpress ); 
  97.  
  98. // Other user 
  99. } else { 
  100. $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; 
  101. $new_title['format'] = esc_attr__( "Edit %s's Profile", bbpress ); 
  102.  
  103. /** Views *****************************************************************/ 
  104.  
  105. // Views 
  106. } elseif ( bbp_is_single_view() ) { 
  107. $new_title['text'] = bbp_get_view_title(); 
  108. $new_title['format'] = esc_attr__( 'View: %s', bbpress ); 
  109.  
  110. /** Search ****************************************************************/ 
  111.  
  112. // Search 
  113. } elseif ( bbp_is_search() ) { 
  114. $new_title['text'] = bbp_get_search_title(); 
  115.  
  116. // This filter is deprecated. Use 'bbp_before_title_parse_args' instead. 
  117. $new_title = apply_filters( 'bbp_raw_title_array', $new_title ); 
  118.  
  119. // Set title array defaults 
  120. $new_title = bbp_parse_args( $new_title, array( 
  121. 'text' => $title,  
  122. 'format' => '%s' 
  123. ), 'title' ); 
  124.  
  125. // Get the formatted raw title 
  126. $new_title = sprintf( $new_title['format'], $new_title['text'] ); 
  127.  
  128. // Filter the raw title 
  129. $new_title = apply_filters( 'bbp_raw_title', $new_title, $sep, $seplocation ); 
  130.  
  131. // Compare new title with original title 
  132. if ( $new_title === $title ) 
  133. return $title; 
  134.  
  135. // Temporary separator, for accurate flipping, if necessary 
  136. $t_sep = '%WP_TITILE_SEP%'; 
  137. $prefix = ''; 
  138.  
  139. if ( !empty( $new_title ) ) 
  140. $prefix = " $sep "; 
  141.  
  142. // sep on right, so reverse the order 
  143. if ( 'right' === $seplocation ) { 
  144. $new_title_array = array_reverse( explode( $t_sep, $new_title ) ); 
  145. $new_title = implode( " $sep ", $new_title_array ) . $prefix; 
  146.  
  147. // sep on left, do not reverse 
  148. } else { 
  149. $new_title_array = explode( $t_sep, $new_title ); 
  150. $new_title = $prefix . implode( " $sep ", $new_title_array ); 
  151.  
  152. // Filter and return 
  153. return apply_filters( 'bbp_title', $new_title, $sep, $seplocation );