get_the_content

Retrieve the post content.

Description

(string) get_the_content( (constant) $more_link_text = null, (bool) $strip_teaser = false ); 

Returns (string)

Parameters (2)

0. $more_link_text — Optional. (constant) => null
Content for when there is more text.
1. $strip_teaser — Optional. (bool) => false
Strip teaser content before the more text. Default is false.

Usage

  1. if ( !function_exists( 'get_the_content' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // Optional. Content for when there is more text. 
  5. $more_link_text = null; 
  6.  
  7. // Optional. Strip teaser content before the more text. Default is false. 
  8. $strip_teaser = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_the_content($more_link_text, $strip_teaser); 
  12.  

Defined (1)

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

/wp-includes/post-template.php  
  1. function get_the_content( $more_link_text = null, $strip_teaser = false ) { 
  2. global $page, $more, $preview, $pages, $multipage; 
  3.  
  4. $post = get_post(); 
  5.  
  6. if ( null === $more_link_text ) { 
  7. $more_link_text = sprintf( 
  8. '<span aria-label="%1$s">%2$s</span>',  
  9. sprintf( 
  10. /** translators: %s: Name of current post */ 
  11. __( 'Continue reading %s' ),  
  12. the_title_attribute( array( 'echo' => false ) ) 
  13. ),  
  14. __( '(more…)' ) 
  15. ); 
  16.  
  17. $output = ''; 
  18. $has_teaser = false; 
  19.  
  20. // If post password required and it doesn't match the cookie. 
  21. if ( post_password_required( $post ) ) 
  22. return get_the_password_form( $post ); 
  23.  
  24. if ( $page > count( $pages ) ) // if the requested page doesn't exist 
  25. $page = count( $pages ); // give them the highest numbered page that DOES exist 
  26.  
  27. $content = $pages[$page - 1]; 
  28. if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 
  29. $content = explode( $matches[0], $content, 2 ); 
  30. if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) 
  31. $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); 
  32.  
  33. $has_teaser = true; 
  34. } else { 
  35. $content = array( $content ); 
  36.  
  37. if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) 
  38. $strip_teaser = true; 
  39.  
  40. $teaser = $content[0]; 
  41.  
  42. if ( $more && $strip_teaser && $has_teaser ) 
  43. $teaser = ''; 
  44.  
  45. $output .= $teaser; 
  46.  
  47. if ( count( $content ) > 1 ) { 
  48. if ( $more ) { 
  49. $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; 
  50. } else { 
  51. if ( ! empty( $more_link_text ) ) 
  52.  
  53. /** 
  54. * Filters the Read More link text. 
  55. * @since 2.8.0 
  56. * @param string $more_link_element Read More link element. 
  57. * @param string $more_link_text Read More text. 
  58. */ 
  59. $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 
  60. $output = force_balance_tags( $output ); 
  61.  
  62. if ( $preview ) // Preview fix for JavaScript bug with foreign languages. 
  63. $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 
  64.  
  65. return $output;