Using WordPress ‘the_content()’ PHP function

The the_content() WordPress PHP function displays the post content, taking into consideration the <!--more--> quicktag for excerpting content on non-single/non-permalink post pages.

Usage

the_content($more_link_text, $strip_teaser);

Parameters

  • $more_link_text (string) Optional: Content for when there is more text. Default: null
  • $strip_teaser (bool) Optional: Strip teaser content before the more text. Default: false

More information

See WordPress Developer Resources: the_content()

Examples

This example displays the post content with the default “Continue reading” link when the <!--more--> tag is present.

the_content();

This example displays the post content with a custom “Read more” link when the <!--more--> tag is present.

the_content('Read more');

Removing teaser content

This example displays the post content without the teaser content before the <!--more--> tag.

the_content(null, true);

This example displays the post content with a custom “Read on” link when the <!--more--> tag is present, and removes the teaser content.

the_content('Read on', true);

Filter the_content() output

This example demonstrates how to filter the output of the the_content() function. In this case, we are replacing all instances of “WordPress” with “WP” in the post content.

add_filter('the_content', 'replace_wordpress_with_wp');

function replace_wordpress_with_wp($content) {
    $content = str_replace('WordPress', 'WP', $content);
    return $content;
}