wppaste
WordPress

render_block_core_query_title( array $attributes, array $content, object $block ): string

Since
5.8.0
Source
wp-includes/blocks/query-title.php:21
Renders the 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

Reaches the database via get_post().

Scaling
Constant

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

Instructions
19–115

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()one call below render_block_core_query_title()
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
!$attributes19–27is_archive(), is_search()
!$attributes && $type === "post-type"35–37is_archive(), is_search(), get_post_type_object()
!$attributes && $type === "post-type"41–45is_archive(), is_search(), __(), get_post_type_object()
!$attributes && $type === "post-type"42–45is_archive(), is_search(), get_the_archive_title(), get_post_type_object()
!$attributes && $type === "post-type"48–53is_archive(), is_search(), get_the_archive_title(), __(), get_post_type_object()
!$attributes && $type !== "post-type"53–57is_archive(), is_search(), class(), sprintf()
!$attributes && $type === "post-type"53–56is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), get_post_type_object()
isset($attributes) && $type === "post-type"53–55is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), get_post_type_object()
!$attributes && $type !== "post-type"59–65is_archive(), is_search(), __(), class(), sprintf()
!$attributes && $type === "post-type"59–64is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), get_post_type_object()
!$attributes && $type !== "post-type"60–65is_archive(), is_search(), get_the_archive_title(), class(), sprintf()
isset($attributes) && $type === "post-type"60–63is_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–70is_archive(), is_search(), get_post_type_object(), class(), sprintf()
!$attributes && $type !== "post-type"66–73is_archive(), is_search(), get_the_archive_title(), __(), class(), sprintf()
!$attributes && $type === "post-type"71–78is_archive(), is_search(), __(), get_post_type_object(), class(), sprintf()
!$attributes && $type !== "post-type"71–76is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), class(), sprintf()
$type !== "post-type" && isset($attributes)71–75is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), class(), sprintf()
isset($attributes) && $type === "post-type"71–74is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), __(), get_search_query(), sprintf(), get_post_type_object()
!$attributes && $type === "post-type"72–78is_archive(), is_search(), get_the_archive_title(), get_post_type_object(), class(), sprintf()
!$attributes && $type === "post-type"73–78is_archive(), is_search(), get_post_type_object(), __(), sprintf(), class(), sprintf()
!$attributes && $type !== "post-type"77–84is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), class(), sprintf()
!$attributes && $type === "post-type"78–86is_archive(), is_search(), get_the_archive_title(), __(), get_post_type_object(), class(), sprintf()
$type !== "post-type" && isset($attributes)78–83is_archive(), is_search(), get_the_archive_title(), __(), __(), get_search_query(), sprintf(), class(), sprintf()
!$attributes && $type === "post-type"79–86is_archive(), is_search(), __(), get_post_type_object(), __(), sprintf(), class(), sprintf()
!$attributes && $type === "post-type"80–86is_archive(), is_search(), get_the_archive_title(), get_post_type_object(), __(), sprintf(), class(), sprintf()
!$attributes && $type === "post-type"83–89is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), get_post_type_object(), class(), sprintf()
isset($attributes) && $type === "post-type"83–88is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), class(), sprintf()
!$attributes && $type === "post-type"86–94is_archive(), is_search(), get_the_archive_title(), __(), get_post_type_object(), __(), sprintf(), class(), sprintf()
!$attributes && $type === "post-type"89–97is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), get_post_type_object(), class(), sprintf()
$type !== "post-type" && isset($attributes)89–94is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), __(), get_search_query(), sprintf(), class(), sprintf()
isset($attributes) && $type === "post-type"90–96is_archive(), is_search(), get_the_archive_title(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), class(), sprintf()
!$attributes && $type === "post-type"91–97is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), get_post_type_object(), __(), sprintf(), class(), sprintf()
isset($attributes) && $type === "post-type"91–96is_archive(), is_search(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), __(), sprintf(), class(), sprintf()
!$attributes && $type === "post-type"97–105is_archive(), is_search(), add_filter(), get_the_archive_title(), remove_filter(), __(), get_post_type_object(), __(), sprintf(), class(), sprintf()
isset($attributes) && $type === "post-type"98–104is_archive(), is_search(), get_the_archive_title(), __(), __(), get_search_query(), sprintf(), get_post_type_object(), __(), sprintf(), class(), sprintf()
isset($attributes) && $type === "post-type"101–107is_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–115is_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

PHPCompiledExecutedBranchesNotes
8.6-dev12819–115221 fewer instruction than PHP 8.5
8.512919–11522
8.412919–11522
8.312919–11522
8.212919–11522
8.112919–115222 fewer instructions than PHP 7.4
7.413119–11622

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

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: &#8220;%s&#8221;' ),				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: &#8220;%s&#8221;' ),				$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.

  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.

7.1.0
Parameter $content retyped from untyped to array.verified against source
6.9.7
Parameter $content added.verified against source
6.9.7
Parameter $block added.verified against source
5.8.0
Introduced.from the docblock

About 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.