bbdev

Topic title in <title> tag, for group forum topic

Jun 1st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. add_filter( 'bp_get_title_parts', 'boss_child_wp_title', 20 );
  3. /**
  4.  * Add the topic title part into <title> tag, when viewing a topic in group forums.
  5.  *
  6.  * @global type $wpdb
  7.  * @param array $title_parts
  8.  * @return array
  9.  */
  10. function boss_child_wp_title( $title_parts ){
  11.     if( function_exists( 'bbp_get_topic_post_type' ) && function_exists( 'bp_is_group_forum_topic' ) && bp_is_group_forum_topic() ){
  12.         $topic_slug = bp_action_variable( 1 );
  13.         if( empty( $topic_slug ) )
  14.             return $title_parts;
  15.        
  16.         //$topic = get_page_by_path( $topic_slug, OBJECT, bbp_get_topic_post_type() );
  17.        
  18.         global $wpdb;
  19.         $topic_title = $wpdb->get_var( $wpdb->prepare(
  20.             "SELECT post_title FROM {$wpdb->posts} WHERE post_type=%s AND post_name=%s",
  21.             bbp_get_topic_post_type(),
  22.             $topic_slug
  23.         ) );
  24.        
  25.         if( empty( $topic_title ) || is_wp_error( $topic_title ) )
  26.             return $title_parts;
  27.        
  28.         //$topic_title = wp_trim_words( $topic_title, 10 );//limit it to 10 words
  29.         $new_parts = array( $topic_title );
  30.         if( !empty( $title_parts ) ){
  31.             foreach( $title_parts as $p ){
  32.                 $new_parts[] = $p;
  33.             }
  34.         }
  35.        
  36.         $title_parts = $new_parts;
  37.     }
  38.     return $title_parts;
  39. }
Add Comment
Please, Sign In to add comment