render_block_core_breadcrumbs( array $attributes, string $content, WP_Block $block ): string
- Since
- 7.0.0
- Source
wp-includes/blocks/breadcrumbs.php:19
core/breadcrumbs block on the server.Compatibility
- WordPress
- since 7.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 2 of the 5 tracked releases, added in 7.0.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 post breadcrumb for hierarchical post types.
Performance profile
How much work a call to render_block_core_breadcrumbs() 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
- 15–23
- Plugin surface
- 1 hook
- 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 363.
Third-party callbacks on 'block_core_breadcrumbs_items' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below render_block_core_breadcrumbs() - serializeserialisation
maybe_unserialize()one call below render_block_core_breadcrumbs()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_breadcrumbs() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($item) | 15 | esc_html() |
| always | 16 | wp_kses_post() |
| always | 22 | esc_html(), esc_url() |
!empty($item) | 23 | wp_kses_post(), esc_url() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 361 | 14–22 | 38 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 363 | 15–23 | 38 | |
| 8.4 | 363 | 15–23 | 38 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 367 | 15–23 | 38 | |
| 8.2 | 367 | 15–23 | 38 | |
| 8.1 | 367 | 15–23 | 38 | |
| 7.4 | 367 | 15–23 | 38 |
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 render_block_core_breadcrumbs() runs, in this order:
- apply_filters( block_core_breadcrumbs_items )filterline 180 (+161 into the body)
Filters the breadcrumb items array before rendering.
Uses · 30
- is_front_page()Determines whether the query is for the front page of the site.
- is_home()Determines whether the query is for the blog homepage.
- get_option()Retrieves an option value based on an option name.
- get_query_var()Retrieves the value of a query variable in the WP_Query class.
- __()Retrieves the translation of $text.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- block_core_breadcrumbs_create_item()Creates a breadcrumb item that's either a link or current page item.
- block_core_breadcrumbs_is_paged()Checks if we're on a paginated view (page 2 or higher).
- block_core_breadcrumbs_get_post_title()Gets a post title with fallback for empty titles.
- block_core_breadcrumbs_create_page_number_item()Creates a "Page X" breadcrumb item for paginated views.
- is_search()Determines whether the query is for a search.
- wp_trim_words()Trims text to a certain number of words.
Show all 30
- get_search_query()Retrieves the contents of the search WordPress query variable.
- is_404()Determines whether the query has resulted in a 404 (returns no results).
- is_archive()Determines whether the query is for an existing archive page.
- block_core_breadcrumbs_get_archive_breadcrumbs()Generates breadcrumb items for archive pages.
- get_post()Retrieves post data given a post ID or post object.
- is_post_type_hierarchical()Determines whether the post type is hierarchical.
- get_object_taxonomies()Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
- get_post_type_object()Retrieves a post type object by name.
- get_post_type_archive_link()Retrieves the permalink for a post type archive.
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
- block_core_breadcrumbs_get_hierarchical_post_type_breadcrumbs()Generates breadcrumb items from hierarchical post type ancestors.
- block_core_breadcrumbs_get_terms_breadcrumbs()Generates breadcrumb items from taxonomy terms.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- 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.
- wp_kses_post()Sanitizes content for allowed HTML tags for post content.
- esc_html()Escaping for HTML blocks.
- esc_url()Checks and cleans a URL.
Source code
function render_block_core_breadcrumbs( $attributes, $content, $block ) { $is_front_page = is_front_page(); if ( ! $attributes['showOnHomePage'] && $is_front_page ) { return ''; } $is_home = is_home(); $page_for_posts = get_option( 'page_for_posts' ); $breadcrumb_items = array(); if ( $attributes['showHomeItem'] ) { // We make `home` a link if not on front page, or if front page // is set to a custom page and is paged. if ( ! $is_front_page || ( 'page' === get_option( 'show_on_front' ) && (int) get_query_var( 'page' ) > 1 ) ) { $breadcrumb_items[] = array( 'label' => __( 'Home' ), 'url' => home_url( '/' ), ); } else { $breadcrumb_items[] = block_core_breadcrumbs_create_item( __( 'Home' ), block_core_breadcrumbs_is_paged() ); } } // Handle home. if ( $is_home ) { // These checks are explicitly nested in order not to execute the `else` branch. if ( $page_for_posts ) { $breadcrumb_items[] = block_core_breadcrumbs_create_item( block_core_breadcrumbs_get_post_title( $page_for_posts ), block_core_breadcrumbs_is_paged() ); } if ( block_core_breadcrumbs_is_paged() ) { $breadcrumb_items[] = block_core_breadcrumbs_create_page_number_item(); } } elseif ( $is_front_page ) { // Handle front page. // This check is explicitly nested in order not to execute the `else` branch. // If front page is set to custom page and is paged, add the page number. if ( (int) get_query_var( 'page' ) > 1 ) { $breadcrumb_items[] = block_core_breadcrumbs_create_page_number_item( 'page' ); } } elseif ( is_search() ) { // Handle search results. $is_paged = block_core_breadcrumbs_is_paged(); /* translators: %s: search query */ $text = sprintf( __( 'Search results for: "%s"' ), wp_trim_words( get_search_query(), 10 ) ); $breadcrumb_items[] = block_core_breadcrumbs_create_item( $text, $is_paged ); // Add the "Page X" as the current page if paginated. if ( $is_paged ) { $breadcrumb_items[] = block_core_breadcrumbs_create_page_number_item(); } } elseif ( is_404() ) { // Handle 404 pages. $breadcrumb_items[] = array( 'label' => __( 'Page not found' ), ); } elseif ( is_archive() ) { // Handle archive pages (taxonomy, post type, date, author archives). $archive_breadcrumbs = block_core_breadcrumbs_get_archive_breadcrumbs(); if ( ! empty( $archive_breadcrumbs ) ) { $breadcrumb_items = array_merge( $breadcrumb_items, $archive_breadcrumbs ); } } else { // Handle single post/page breadcrumbs. if ( ! isset( $block->context['postId'] ) || ! isset( $block->context['postType'] ) ) { return ''; } $post_id = $block->context['postId']; $post_type = $block->context['postType']; $post = get_post( $post_id ); if ( ! $post ) { return ''; } // For non-hierarchical post types with parents (e.g., attachments), build trail for the parent. $post_parent = $post->post_parent; $parent_post = null; if ( ! is_post_type_hierarchical( $post_type ) && $post_parent ) { $parent_post = get_post( $post_parent );Changelog
Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/breadcrumbs.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.