render_block_core_term_name( array $attributes, string $content, WP_Block $block ): string
- Since
- 6.9.0
- Source
wp-includes/blocks/term-name.php:19
core/term-name block on the server.Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.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 name of the current taxonomy term wrapped inside a heading tag.
Performance profile
How much work a call to render_block_core_term_name() 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
- 13–85
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_term().
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 94.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_term()called directly - hookthird-party callbacks
apply_filters()one call below render_block_core_term_name()
Further down the call graph this can also reach option, 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 · 10 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_term_name() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) | 13–17 | get_queried_object() |
!isset($value) && is_wp_error() | 17–21 | get_queried_object(), is_wp_error() |
isset($value) | 23 | get_term() |
isset($value) && is_wp_error() | 27 | get_term(), is_wp_error() |
!isset($value) && !is_wp_error() | 49–62 | get_queried_object(), is_wp_error(), class(), sprintf() |
isset($value) && !is_wp_error() | 59–68 | get_term(), is_wp_error(), class(), sprintf() |
!isset($value) && isset($attributes) && $attributes | 59–70 | get_queried_object(), is_wp_error(), get_term_link(), is_wp_error(), class(), sprintf() |
!isset($value) && !is_wp_error() && isset($attributes) && $attributes | 68–79 | get_queried_object(), is_wp_error(), get_term_link(), is_wp_error(), esc_url(), sprintf(), class(), sprintf() |
isset($value) && isset($attributes) && $attributes | 69–76 | get_term(), is_wp_error(), get_term_link(), is_wp_error(), class(), sprintf() |
isset($value) && !is_wp_error() && isset($attributes) && $attributes | 78–85 | get_term(), is_wp_error(), get_term_link(), is_wp_error(), esc_url(), sprintf(), class(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 94 | 13–85 | 12 | |
| 8.5 | 94 | 13–85 | 12 | |
| 8.4 | 94 | 13–85 | 12 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 97 | 13–88 | 12 | |
| 8.2 | 97 | 13–88 | 12 | |
| 8.1 | 97 | 13–88 | 12 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 98 | 13–89 | 12 |
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 · 6
- get_term()Gets all term data from database by term ID.
- get_queried_object()Retrieves the currently queried object.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_term_link()Generates a permalink for a taxonomy term archive.
- esc_url()Checks and cleans a URL.
- 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_term_name( $attributes, $content, $block ) { $term_name = ''; // Get term from context or from the current query. if ( isset( $block->context['termId'] ) && isset( $block->context['taxonomy'] ) ) { $term = get_term( $block->context['termId'], $block->context['taxonomy'] ); } else { $term = get_queried_object(); if ( ! $term instanceof WP_Term ) { $term = null; } } if ( ! $term || is_wp_error( $term ) ) { return ''; } $term_name = $term->name; $level = $attributes['level'] ?? 0; $tag_name = 0 === $level ? 'p' : 'h' . (int) $level; if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { $term_link = get_term_link( $term ); if ( ! is_wp_error( $term_link ) ) { $term_name = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $term_link ), $term_name ); } } $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 ) ) ); return sprintf( '<%1$s %2$s>%3$s</%1$s>', $tag_name, $wrapper_attributes, $term_name );}Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/term-name.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.