wppaste
WordPress

get_the_content( string $more_link_text = null, bool $strip_teaser = false, WP_Post|object|int $post = null ): string

Since
0.71, 5.2.0
Source
wp-includes/post-template.php:279
Retrieves the post content.

Compatibility

WordPress
since 5.2.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$strip_teaserbooloptional
Strip teaser content before the more text. Default false.Default: false
$postWP_Post|object|intoptional
WP_Post instance or Post ID/object. Default null.Default: null

Return value

string

Performance profile

How much work a call to get_the_content() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
32–150

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 173.

Plugin surface
1 hook

Third-party callbacks on 'the_content_more_link' run inside this call, and their cost is not bounded by anything here.

Called by
12

12 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below get_the_content()

Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 49 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_the_content() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$_post instanceof && $post !== null && $more_link_text !== null && post_password_required()32get_post(), generate_postdata(), post_password_required(), get_the_password_form()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && post_password_required()36get_post(), did_action(), generate_postdata(), post_password_required(), get_the_password_form()
$_post instanceof && $post !== null && $more_link_text === null && post_password_required()53get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), get_the_password_form()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && post_password_required()57get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), get_the_password_form()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && !preg_match()59–80get_post(), generate_postdata(), post_password_required(), preg_match()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && !preg_match()63–84get_post(), did_action(), generate_postdata(), post_password_required(), preg_match()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && !preg_match() && !$elements && empty($more_link_text)67–80get_post(), generate_postdata(), post_password_required(), preg_match(), force_balance_tags()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && !preg_match()68–85get_post(), did_action(), compact(), post_password_required(), preg_match()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && !preg_match() && !$elements && empty($more_link_text)71–84get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && preg_match()73–99get_post(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && !preg_match() && !$elements && empty($more_link_text)76–85get_post(), did_action(), compact(), post_password_required(), preg_match(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && preg_match()77–103get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode()
37 further outcomes, up to 150 instructions
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && !preg_match()80–101get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && preg_match() && !$elements && empty($more_link_text)81–99get_post(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), force_balance_tags()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && preg_match()82–104get_post(), did_action(), compact(), post_password_required(), preg_match(), has_block(), explode()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && !preg_match() && !$elements && !empty($more_link_text)84–97get_post(), generate_postdata(), post_password_required(), preg_match(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text)84–108get_post(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && !preg_match()84–105get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !$elements && empty($more_link_text)85–103get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && !preg_match() && !$elements && !empty($more_link_text)88–101get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text)88–112get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && !preg_match() && !$elements && empty($more_link_text)88–101get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), force_balance_tags()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !$elements && empty($more_link_text)90–104get_post(), did_action(), compact(), post_password_required(), preg_match(), has_block(), explode(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !$elements92–108get_post(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && !preg_match() && !$elements && empty($more_link_text)92–105get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), force_balance_tags()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && !preg_match() && !$elements && !empty($more_link_text)93–102get_post(), did_action(), compact(), post_password_required(), preg_match(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text)93–110get_post(), did_action(), compact(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && preg_match()94–120get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !$elements96–112get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && preg_match() && !$elements && !empty($more_link_text)98–116get_post(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && preg_match()98–124get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !$elements101–110get_post(), did_action(), compact(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !$elements && !empty($more_link_text)102–120get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && preg_match() && !$elements && empty($more_link_text)102–120get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && !preg_match() && !$elements && !empty($more_link_text)105–118get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text)105–129get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && preg_match() && !$elements && empty($more_link_text)106–124get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), force_balance_tags()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !$elements && !empty($more_link_text)107–121get_post(), did_action(), compact(), post_password_required(), preg_match(), has_block(), explode(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text) && !$elements109–125get_post(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && !preg_match() && !$elements && !empty($more_link_text)109–122get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text)109–133get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text) && !$elements113–129get_post(), did_action(), generate_postdata(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && preg_match() && !empty($matches) && !$elements113–129get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && preg_match() && !empty($matches) && !$elements117–133get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), force_balance_tags()
$_post instanceof && $post === null && did_action() && $more_link_text !== null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text) && !$elements118–127get_post(), did_action(), compact(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && preg_match() && !$elements && !empty($more_link_text)119–137get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && preg_match() && !$elements && !empty($more_link_text)123–141get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post !== null && $more_link_text === null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text) && !$elements130–146get_post(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), get_permalink(), apply_filters(), force_balance_tags()
$_post instanceof && $post === null && !did_action() && $more_link_text === null && !post_password_required() && preg_match() && !empty($matches) && !empty($more_link_text) && !$elements134–150get_post(), did_action(), generate_postdata(), __(), echo(), the_title_attribute(), __(), sprintf(), post_password_required(), preg_match(), has_block(), explode(), wp_kses_no_null(), strip_tags(), get_permalink(), apply_filters(), force_balance_tags()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev17332–15019
8.517332–15019
8.417332–150198 fewer instructions than PHP 8.3
8.318132–15819
8.218132–15819
8.118132–158191 fewer instruction than PHP 7.4
7.418232–15919

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while get_the_content() runs, in this order:

  1. apply_filters( the_content_more_link )filterline 376 (+97 into the body)

    Filters the Read More link text.

Uses · 13

Show all 13

Used by · 12

Source code

function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {	global $page, $more, $preview, $pages, $multipage; 	$_post = get_post( $post ); 	if ( ! ( $_post instanceof WP_Post ) ) {		return '';	} 	/*	 * Use the globals if the $post parameter was not specified,	 * but only after they have been set up in setup_postdata().	 */	if ( null === $post && did_action( 'the_post' ) ) {		$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );	} else {		$elements = generate_postdata( $_post );	} 	if ( null === $more_link_text ) {		$more_link_text = sprintf(			'<span aria-label="%1$s">%2$s</span>',			sprintf(				/* translators: %s: Post title. */				__( 'Continue reading %s' ),				the_title_attribute(					array(						'echo' => false,						'post' => $_post,					)				)			),			__( '(more&hellip;)' )		);	} 	$output     = '';	$has_teaser = false; 	// If post password required and it doesn't match the cookie.	if ( post_password_required( $_post ) ) {		return get_the_password_form( $_post );	} 	// If the requested page doesn't exist.	if ( $elements['page'] > count( $elements['pages'] ) ) {		// Give them the highest numbered page that DOES exist.		$elements['page'] = count( $elements['pages'] );	} 	$page_no = $elements['page'];	$content = $elements['pages'][ $page_no - 1 ];	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {		if ( has_block( 'more', $content ) ) {			// Remove the core/more block delimiters. They will be left over after $content is split up.			$content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );		} 		$content = explode( $matches[0], $content, 2 ); 		if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {			$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );		} 		$has_teaser = true;	} else {		$content = array( $content );	} 	if ( str_contains( $_post->post_content, '<!--noteaser-->' )		&& ( ! $elements['multipage'] || 1 === $elements['page'] )	) {		$strip_teaser = true;	} 	$teaser = $content[0]; 	if ( $elements['more'] && $strip_teaser && $has_teaser ) {		$teaser = '';	}

Changelog

Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.2.0
Added the $post parameter.from the docblock
0.71
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/post-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.