p2_the_title

Generate a nicely formatted post title.

Description

(string) p2_the_title( $before = '<h2>', $after = '</h2>', (bool) $returner = false ); 

Ignore empty titles, titles that are auto-generated from the first part of the post_content

Returns (string)

$out nicely formatted title, will be empty string if no title

Parameters (3)

0. $before — Optional. (string) => '

'

Content to prepend to title
1. $after — Optional. (string) => ''
Content to append to title
2. $returner — Optional. (bool) => false
Echo or return

Usage

  1. if ( !function_exists( 'p2_the_title' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-groupblog/themes/p2/functions.php'; 
  3.  
  4. // content to prepend to title 
  5. $before = '

    '; 

  6.  
  7. // content to append to title 
  8. $after = ''; 
  9.  
  10. // echo or return 
  11. $returner = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = p2_the_title($before, $after, $returner); 
  15.  

Defined (1)

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

/themes/p2/functions.php  
  1. function p2_the_title( $before = '<h2>', $after = '</h2>', $returner = false ) { 
  2. global $post; 
  3.  
  4. $temp = $post; 
  5. $t = apply_filters( 'the_title', $temp->post_title ); 
  6. $title = $temp->post_title; 
  7. $content = $temp->post_content; 
  8. $pos = 0; 
  9. $out = ''; 
  10.  
  11. // Don't show post title if turned off in options or title is default text 
  12. if ( 1 != (int) get_option( 'prologue_show_titles' ) || 'Post Title' == $title ) 
  13. return false; 
  14.  
  15. $content = trim( $content ); 
  16. $title = trim( $title ); 
  17. $title = preg_replace( '/\.\.\.$/', '', $title ); 
  18. $title = str_replace( "\n", ' ', $title ); 
  19. $title = str_replace( ' ', ' ', $title); 
  20. $content = str_replace( "\n", ' ', strip_tags( $content) ); 
  21. $content = str_replace( ' ', ' ', $content ); 
  22. $content = trim( $content ); 
  23. $title = trim( $title ); 
  24.  
  25. // Clean up links in the title 
  26. if ( false !== strpos( $title, 'http' ) ) { 
  27. $split = @str_split( $content, strpos( $content, 'http' ) ); 
  28. $content = $split[0]; 
  29. $split2 = @str_split( $title, strpos( $title, 'http' ) ); 
  30. $title = $split2[0]; 
  31.  
  32. // Avoid processing an empty title 
  33. if ( '' == $title ) 
  34. return false; 
  35.  
  36. // Avoid processing the title if it's the very first part of the post content 
  37. // Which is the case with most "status" posts 
  38. $pos = strpos( $content, $title ); 
  39. if ( false === $pos || 0 < $pos ) { 
  40. if ( is_single() ) 
  41. $out = $before . $t . $after; 
  42. else 
  43. $out = $before . '<a href="' . get_permalink( $temp->ID ) . '">' . $t . ' </a>' . $after; 
  44.  
  45. if ( $returner ) 
  46. return $out; 
  47. else 
  48. echo $out;