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
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
$more_link_textstringoptional- Content for when there is more text.Default:
null $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
- Scaling
- Constant
- Instructions
- 32–150
- Plugin surface
- 1 hook
- Called by
- 12
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 173.
Third-party callbacks on 'the_content_more_link' run inside this call, and their cost is not bounded by anything here.
12 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
$_post instanceof && $post !== null && $more_link_text !== null && post_password_required() | 32 | get_post(), generate_postdata(), post_password_required(), get_the_password_form() |
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && post_password_required() | 36 | get_post(), did_action(), generate_postdata(), post_password_required(), get_the_password_form() |
$_post instanceof && $post !== null && $more_link_text === null && post_password_required() | 53 | get_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() | 57 | get_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–80 | get_post(), generate_postdata(), post_password_required(), preg_match() |
$_post instanceof && $post === null && !did_action() && $more_link_text !== null && !post_password_required() && !preg_match() | 63–84 | get_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–80 | get_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–85 | get_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–84 | get_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–99 | get_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–85 | get_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–103 | get_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–101 | get_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–99 | get_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–104 | get_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–97 | get_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–108 | get_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–105 | get_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–103 | get_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–101 | get_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–112 | get_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–101 | get_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–104 | get_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) && !$elements | 92–108 | get_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–105 | get_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–102 | get_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–110 | get_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–120 | get_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) && !$elements | 96–112 | get_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–116 | get_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–124 | get_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) && !$elements | 101–110 | get_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–120 | get_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–120 | get_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–118 | get_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–129 | get_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–124 | get_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–121 | get_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) && !$elements | 109–125 | get_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–122 | get_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–133 | get_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) && !$elements | 113–129 | get_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) && !$elements | 113–129 | get_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) && !$elements | 117–133 | get_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) && !$elements | 118–127 | get_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–137 | get_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–141 | get_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) && !$elements | 130–146 | get_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) && !$elements | 134–150 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 173 | 32–150 | 19 | |
| 8.5 | 173 | 32–150 | 19 | |
| 8.4 | 173 | 32–150 | 19 | 8 fewer instructions than PHP 8.3 |
| 8.3 | 181 | 32–158 | 19 | |
| 8.2 | 181 | 32–158 | 19 | |
| 8.1 | 181 | 32–158 | 19 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 182 | 32–159 | 19 |
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:
- apply_filters( the_content_more_link )filterline 376 (+97 into the body)
Filters the Read More link text.
Uses · 13
- get_post()Retrieves post data given a post ID or post object.
- did_action()Retrieves the number of times an action has been fired during the current request.
- generate_postdata()Generates post data.
- __()Retrieves the translation of $text.
- the_title_attribute()Sanitizes the current title when retrieving or displaying.
- post_password_required()Determines whether the post requires password and whether a correct password has been provided.
- get_the_password_form()Retrieves protected post password form content.
- has_block()Determines whether a $post or a string contains a specific block type.
- wp_kses_no_null()Removes any invalid control characters in a text string.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_permalink()Retrieves the full permalink for the current post or post ID.
Show all 13
- force_balance_tags()Balances tags of string using a modified stack.
Used by · 12
- get_the_content_feed()Retrieves the post content for feeds.
- render_block_core_post_content()Renders the `core/post-content` block on the server.
- the_content()Displays the post content.
- the_content_rss()Display the post content for the feed.
- twenty_twenty_one_print_first_instance_of_block()Print the first instance of a block in the content, and then break away.
- twentyeleven_get_first_url()Return the first link from the post content. If none found, the post permalink is used as a fallback.
- twentyeleven_get_gallery_images()Retrieve the IDs for images in a gallery.
- twentyeleven_url_grabber()Return the URL for the first link found in the post content.
- twentyfifteen_get_link_url()Return the post URL.
- twentyten_get_gallery_images()Retrieve the IDs for images in a gallery.
- twentythirteen_get_link_url()Return the post URL.
- wp_trim_excerpt()Generates an excerpt from the content, if needed.
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…)' ) ); } $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.
Signature, return type and hooks compared across 5 parsed releases.
$post parameter.from the docblockAbout 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.