the_content()WP 0.71

Display the post content. It is template tag and must be used inside the loop.

Besides using this function in the loop, it can be used on a single page like page.php, single.php.

When the function is used on archive pages (not a single page) and if the content uses the tag-separator <!--more-->, the_content() will cut the text: anything above <!--more--> will be shown, and everything after this tag will be cut and replaced with link "read more" (link text can be changed by specifying the parameter $more_link_text).

1 time — 0.019477 sec (extremely slow) | 50000 times — 11.65 sec (slow) | PHP 7.1.11, WP 4.9.6
Hooks from the function

Return

null. Nothing (null). Shows on the screen formatted post content.

Usage

<?php the_content( $more_link_text, $strip_teaser ); ?>
$more_link_text(string)
Text of the read more... link. Default is: (more...)
Default: null
$strip_teaser(true/false)

Strip teaser content before the more text.

The word "teaser" means the attracting text before the <!--more-->. If you set this parameter to true, the content before the <!--more--> tag on the is_single() page will be removed.

Also, you can delete content before the more tag by specifying the <!--noteaser--> tag anywhere in the post content. Usually <!--noteaser--> tag is placed right after <!--more--> tag.

Default: false

Examples

0

#1 Changing "more..." link text

If you want to change the standard link text that displays when the content is split by the <!--more--> then specify the required text in the first parameter of the function:

<?php the_content( 'Go to full text...' ); ?>
0

#2 Insert the post title in the "more..." link text

You can use the_title() function to insert post title into "more" text of the link:

<?php the_content( 'reed more: ' . the_title('', '', false) ); ?>
0

#3 Change the behavior of the function, relative to the text clipping tag <!--more-->

If the function does not cut the text on the tag <!--more--> or vice versa, cuts where we don't need it, then you can change the variable $more, thereby specifying the cut (0) or not cut (1) the text.

<?php
global $more;    // Declare variable $more as a global (before the WordPress Loop).
$more = 0;       // Change the value of the variable to show only the text before the more tag.
the_content( 'reed more...' );
?>

or if you want to leave the content as is:

<?php
global $more;
$more = 1;       // ignore more tag (do not cut).
the_content();
?>
0

#4 Ignore the "more" tag for sticky posts

This example displays full content for sticky posts (even if they have the "more" tag), but the rest of the posts will be truncated:

<?php
global $more; // Let's declare $more variable as global.
if( is_sticky() ){
	$more = 1;
	the_content();
}
else {
	$more = 0;
	the_content( 'Read the rest of this entry »' );
}
?>
0

#5 Alternative useage

If you want to get the content of a post for processing in php but not display it, you can use the get_the_content() function:

$content = get_the_content();

However, you should keep in mind that the resulting content (which is now in the $content variable) is NOT filtered. To filter it you need to run it through the filter the_content:

$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]&gt;', $content );

Changelog

Since 0.71 Introduced.

the_content() code WP 6.4.3

function the_content( $more_link_text = null, $strip_teaser = false ) {
	$content = get_the_content( $more_link_text, $strip_teaser );

	/**
	 * Filters the post content.
	 *
	 * @since 0.71
	 *
	 * @param string $content Content of the current post.
	 */
	$content = apply_filters( 'the_content', $content );
	$content = str_replace( ']]>', ']]&gt;', $content );
	echo $content;
}