render_block_core_query_title( array $attributes, array $content, object $block ): string
- Since
- 5.8.0
- Source
wp-includes/blocks/query-title.php:21
core/query-title block on the server.Description
For now it supports Archive title, Search title, and Post Type Label, using queried object information
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.
$contentarray- Block content.
$blockobject- Block instance.
Return value
string- Returns the query title based on the queried object.
Performance profile
How much work a call to render_block_core_query_title() 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
- 19–115
- 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, depending on the branch taken. The body compiles to 129.
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_post()one call below render_block_core_query_title() - hookthird-party callbacks
apply_filters()one call below render_block_core_query_title()
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 · 37 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_query_title() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$attributes | 19–27 | is_archive(), is_search() |
!$attributes && $type === "post-type" | 35–37 | is_archive(), is_search(), get_post_type_object() |
!$attributes && $type === "post-type" | 41–45 | is_archive(), is_search(), __(), get_post_type_object() |
!$attributes && $type === "post-type" | 42–45 | is_archive(), is_search(), get_the_archive_title(), get_post_type_object() |
!$attributes && $type === "post-type" | 48–53 | is_archive(), is_search(), get_the_archive_title(), __(), get_post_type_object() |
!$attributes && $type !== "post-type" | 53–57 | is_archive(), is_search(), class(), sprintf() |
!$attributes && $type === "post-type" | 53–56 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), get_post_type_object() |
isset($attributes) && $type === "post-type" | 53–55 | is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), get_post_type_object() |
!$attributes && $type !== "post-type" | 59–65 | is_archive(), is_search(), __(), class(), sprintf() |
!$attributes && $type === "post-type" | 59–64 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), get_post_type_object() |
!$attributes && $type !== "post-type" | 60–65 | is_archive(), is_search(), get_the_archive_title(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 60–63 | is_archive(), is_search(), get_the_archive_title(), __(), __(), get_search_query(), sprintf(), get_post_type_object() |
25 further outcomes, up to 115 instructions
!$attributes && $type === "post-type" | 65–70 | is_archive(), is_search(), get_post_type_object(), class(), sprintf() |
!$attributes && $type !== "post-type" | 66–73 | is_archive(), is_search(), get_the_archive_title(), __(), class(), sprintf() |
!$attributes && $type === "post-type" | 71–78 | is_archive(), is_search(), __(), get_post_type_object(), class(), sprintf() |
!$attributes && $type !== "post-type" | 71–76 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), class(), sprintf() |
$type !== "post-type" && isset($attributes) | 71–75 | is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 71–74 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), __(), get_search_query(), sprintf(), get_post_type_object() |
!$attributes && $type === "post-type" | 72–78 | is_archive(), is_search(), get_the_archive_title(), get_post_type_object(), class(), sprintf() |
!$attributes && $type === "post-type" | 73–78 | is_archive(), is_search(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
!$attributes && $type !== "post-type" | 77–84 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), class(), sprintf() |
!$attributes && $type === "post-type" | 78–86 | is_archive(), is_search(), get_the_archive_title(), __(), get_post_type_object(), class(), sprintf() |
$type !== "post-type" && isset($attributes) | 78–83 | is_archive(), is_search(), get_the_archive_title(), __(), __(), get_search_query(), sprintf(), class(), sprintf() |
!$attributes && $type === "post-type" | 79–86 | is_archive(), is_search(), __(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
!$attributes && $type === "post-type" | 80–86 | is_archive(), is_search(), get_the_archive_title(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
!$attributes && $type === "post-type" | 83–89 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), get_post_type_object(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 83–88 | is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), class(), sprintf() |
!$attributes && $type === "post-type" | 86–94 | is_archive(), is_search(), get_the_archive_title(), __(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
!$attributes && $type === "post-type" | 89–97 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), get_post_type_object(), class(), sprintf() |
$type !== "post-type" && isset($attributes) | 89–94 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), __(), get_search_query(), sprintf(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 90–96 | is_archive(), is_search(), get_the_archive_title(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), class(), sprintf() |
!$attributes && $type === "post-type" | 91–97 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 91–96 | is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
!$attributes && $type === "post-type" | 97–105 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 98–104 | is_archive(), is_search(), get_the_archive_title(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 101–107 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), class(), sprintf() |
isset($attributes) && $type === "post-type" | 109–115 | is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), __(), sprintf(), class(), sprintf() |
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 | 128 | 19–115 | 22 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 129 | 19–115 | 22 | |
| 8.4 | 129 | 19–115 | 22 | |
| 8.3 | 129 | 19–115 | 22 | |
| 8.2 | 129 | 19–115 | 22 | |
| 8.1 | 129 | 19–115 | 22 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 131 | 19–116 | 22 |
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 · 10
- is_archive()Determines whether the query is for an existing archive page.
- is_search()Determines whether the query is for a search.
- get_post_type()Retrieves the post type of the current post or of a given post.
- add_filter()Adds a callback function to a filter hook.
- get_the_archive_title()Retrieves the archive title based on the queried object.
- remove_filter()Removes a callback function from a filter hook.
- __()Retrieves the translation of $text.
- get_search_query()Retrieves the contents of the search WordPress query variable.
- get_post_type_object()Retrieves a post type object by name.
- 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_query_title( $attributes, $content, $block ) { $type = $attributes['type'] ?? null; $is_archive = is_archive(); $is_search = is_search(); $post_type = $block->context['query']['postType'] ?? get_post_type(); if ( ! $type || ( 'archive' === $type && ! $is_archive ) || ( 'search' === $type && ! $is_search ) || ( 'post-type' === $type && ! $post_type ) ) { return ''; } $title = ''; if ( $is_archive ) { $show_prefix = $attributes['showPrefix'] ?? true; if ( ! $show_prefix ) { add_filter( 'get_the_archive_title_prefix', '__return_empty_string', 1 ); $title = get_the_archive_title(); remove_filter( 'get_the_archive_title_prefix', '__return_empty_string', 1 ); } else { $title = get_the_archive_title(); } } if ( $is_search ) { $title = __( 'Search results' ); if ( isset( $attributes['showSearchTerm'] ) && $attributes['showSearchTerm'] ) { $title = sprintf( /* translators: %s is the search term. */ __( 'Search results for: “%s”' ), get_search_query() ); } } if ( 'post-type' === $type ) { $post_type_object = get_post_type_object( $post_type ); if ( ! $post_type_object ) { return ''; } $post_type_name = $post_type_object->labels->singular_name; $show_prefix = $attributes['showPrefix'] ?? true; if ( $show_prefix ) { $title = sprintf( /* translators: %s is the post type name. */ __( 'Post Type: “%s”' ), $post_type_name ); } else { $title = $post_type_name; } } $level = (int) ( $attributes['level'] ?? 1 ); $tag_name = 0 === $level ? 'p' : 'h' . $level; $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); return sprintf( '<%1$s %2$s>%3$s</%1$s>', $tag_name, $wrapper_attributes, $title );}Changelog
Introduced in 5.8.0. 3 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$content retyped from untyped to array.verified against source$content added.verified against source$block added.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/query-title.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.