render_block_core_post_excerpt( array $attributes, string $content, WP_Block $block ): string
- Since
- 5.8.0
- Source
wp-includes/blocks/post-excerpt.php:18
core/post-excerpt block on the server.Compatibility
- WordPress
- since 5.8.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
$attributesarray- Block attributes.
$contentstring- Block default content.
$blockWP_Block- Block instance.
Return value
string- Returns the filtered post excerpt for the current post wrapped inside "p" tags.
Performance profile
How much work a call to render_block_core_post_excerpt() 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
- 5
- Plugin surface
- None
- Called by
- 0
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. The body compiles to 118.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below render_block_core_post_excerpt() - querycontent query
get_post()one call below render_block_core_post_excerpt() - optionoption read or write
get_option()one call below render_block_core_post_excerpt()
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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_post_excerpt() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 118 | 5 | 9 | |
| 8.5 | 118 | 5 | 9 | |
| 8.4 | 118 | 5 | 9 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 121 | 5 | 9 | |
| 8.2 | 121 | 5 | 9 | |
| 8.1 | 121 | 5 | 9 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 122 | 5 | 9 |
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.
Uses · 8
- esc_url()Checks and cleans a URL.
- get_the_permalink()Retrieves the full permalink for the current post or post ID.
- wp_kses_post()Sanitizes content for allowed HTML tags for post content.
- add_filter()Adds a callback function to a filter hook.
- get_the_excerpt()Retrieves the post excerpt.
- remove_filter()Removes a callback function from a filter hook.
- wp_trim_words()Trims text to a certain number of words.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
Source code
function render_block_core_post_excerpt( $attributes, $content, $block ) { if ( ! isset( $block->context['postId'] ) ) { return ''; } $more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : ''; $filter_excerpt_more = static function ( $more ) use ( $more_text ) { return empty( $more_text ) ? $more : ''; }; /** * Some themes might use `excerpt_more` filter to handle the * `more` link displayed after a trimmed excerpt. Since the * block has a `more text` attribute we have to check and * override if needed the return value from this filter. * So if the block's attribute is not empty override the * `excerpt_more` filter and return nothing. This will * result in showing only one `read more` link at a time. * * This hook needs to be applied before the excerpt is retrieved with get_the_excerpt. * Otherwise, the read more link filter from the theme is not removed. */ add_filter( 'excerpt_more', $filter_excerpt_more ); /* * The purpose of the excerpt length setting is to limit the length of both * automatically generated and user-created excerpts. * Because the excerpt_length filter only applies to auto generated excerpts, * wp_trim_words is used instead. * * To ensure the block's excerptLength setting works correctly for auto-generated * excerpts, we temporarily override excerpt_length to 101 (the max block setting) * so that wp_trim_excerpt doesn't pre-trim the content before wp_trim_words can * apply the user's desired length. */ $excerpt_length = $attributes['excerptLength']; add_filter( 'excerpt_length', 'block_core_post_excerpt_excerpt_length', PHP_INT_MAX ); $excerpt = get_the_excerpt( $block->context['postId'] ); remove_filter( 'excerpt_length', 'block_core_post_excerpt_excerpt_length', PHP_INT_MAX ); if ( isset( $excerpt_length ) ) { $excerpt = wp_trim_words( $excerpt, $excerpt_length ); } $classes = array(); if ( isset( $attributes['textAlign'] ) ) { $classes[] = 'has-text-align-' . $attributes['textAlign']; } if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { $classes[] = 'has-link-color'; } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); $content = '<p class="wp-block-post-excerpt__excerpt">' . $excerpt; $show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine']; if ( $show_more_on_new_line && ! empty( $more_text ) ) { $content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>'; } else { $content .= " $more_text</p>"; } remove_filter( 'excerpt_more', $filter_excerpt_more ); return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content );}Changelog
Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/post-excerpt.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.