render_block_core_navigation_link( array $attributes, string $content, WP_Block $block ): string
- Since
- 5.9.0
- Source
wp-includes/blocks/navigation-link.php:187
core/navigation-link block.Compatibility
- WordPress
- since 5.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 every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$attributesarray- The block attributes.
$contentstring- The saved content.
$blockWP_Block- The parsed block.
Return value
string- Returns the post content with the legacy widget added.
Performance profile
How much work a call to render_block_core_navigation_link() 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
- 69–131
- 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 185.
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_navigation_link() - hookthird-party callbacks
apply_filters()one call below render_block_core_navigation_link() - optionoption read or write
get_option()one call below render_block_core_navigation_link()
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 · 54 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_navigation_link() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() && !isset($attributes) | 69–84 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && !isset($attributes) | 75–92 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() | 76–92 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() && !isset($attributes) && isset($value) | 80–94 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() | 80–94 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 82–100 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), wp_kses_post() |
$block && $value && !is_post_type_archive() && !isset($attributes) && isset($value) | 83–95 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 83–98 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), wp_kses_post(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() | 84–96 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && !isset($attributes) && isset($value) | 86–102 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 86–102 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() && isset($value) | 87–102 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), block_core_shared_navigation_render_submenu_icon() |
42 further outcomes, up to 131 instructions
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() | 87–102 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr() |
!empty($attributes) && $block && $value && !is_post_type_archive() && !isset($attributes) && isset($value) | 89–103 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
$block && $value && !is_post_type_archive() && isset($value) | 90–103 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 90–106 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 90–104 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() && isset($value) | 91–104 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 93–110 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 93–110 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 94–108 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), wp_kses_post(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
$block && $value && !is_post_type_archive() && isset($value) | 94–105 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 94–108 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() && isset($value) | 95–106 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() | 95–106 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 96–111 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 97–109 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), wp_kses_post(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 97–112 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
$block && $value && !is_post_type_archive() && isset($value) | 98–107 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 98–110 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() && isset($value) | 98–112 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 100–113 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 101–116 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 101–114 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
$block && $value && !is_post_type_archive() && isset($value) | 101–113 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() | 101–116 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), wp_kses_post() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($attributes) | 101–114 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 104–117 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 104–115 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 104–120 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 105–118 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && $block && $value && !is_post_type_archive() && isset($value) | 106–116 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 107–121 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 108–119 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 109–120 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
$block && $value && !is_post_type_archive() && isset($value) | 109–117 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($attributes) | 109–120 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 112–121 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 112–126 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($attributes) && isset($value) | 112–124 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($value) | 115–127 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($attributes) && isset($value) | 115–125 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
!defined('IS_GUTENBERG_PLUGIN') && !empty($attributes) && $block && $value && !is_post_type_archive() && isset($attributes) && isset($value) | 120–130 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_shared_navigation_render_submenu_icon() |
!empty($attributes) && $block && $value && !is_post_type_archive() && isset($attributes) && isset($value) | 123–131 | block_core_shared_navigation_item_should_render(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post(), gutenberg_block_core_shared_navigation_render_submenu_icon() |
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 | 185 | 69–131 | 30 | |
| 8.5 | 185 | 69–131 | 30 | |
| 8.4 | 185 | 69–131 | 30 | 7 fewer instructions than PHP 8.3 |
| 8.3 | 192 | 75–138 | 30 | |
| 8.2 | 192 | 75–138 | 30 | |
| 8.1 | 192 | 75–138 | 30 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 193 | 75–138 | 30 |
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 · 11
- block_core_shared_navigation_item_should_render()Checks if a navigation item should render based on post status.
- get_queried_object_id()Retrieves the ID of the currently queried object.
- get_queried_object()Retrieves the currently queried object.
- is_post_type_archive()Determines whether the query is for an existing post type archive page.
- get_post_type_archive_link()Retrieves the permalink for a post type archive.
- 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.
- esc_url()Checks and cleans a URL.
- block_core_navigation_link_maybe_urldecode()Decodes a url if it's encoded, returning the same url if not.
- esc_attr()Escaping for HTML attributes.
- wp_kses_post()Sanitizes content for allowed HTML tags for post content.
- block_core_shared_navigation_render_submenu_icon()Returns the submenu SVG chevron icon.
Source code
function render_block_core_navigation_link( $attributes, $content, $block ) { // Check if this navigation item should render based on post status. if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { $should_render = gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block ); } else { $should_render = block_core_shared_navigation_item_should_render( $attributes, $block ); } if ( ! $should_render ) { return ''; } // Don't render the block's subtree if it has no label. if ( empty( $attributes['label'] ) ) { return ''; } $classes = array(); // Render inner blocks first to check if any menu items will actually display. $inner_blocks_html = ''; foreach ( $block->inner_blocks as $inner_block ) { $inner_blocks_html .= $inner_block->render(); } $has_submenu = ! empty( trim( $inner_blocks_html ) ); $css_classes = trim( implode( ' ', $classes ) ); $kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] ); $is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind ); if ( is_post_type_archive() && ! empty( $attributes['url'] ) ) { $queried_archive_link = get_post_type_archive_link( get_queried_object()->name ); if ( $attributes['url'] === $queried_archive_link ) { $is_active = true; } } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) . ( $is_active ? ' current-menu-item' : '' ), ) ); $html = '<li ' . $wrapper_attributes . '>' . '<a class="wp-block-navigation-item__content" '; // Start appending HTML attributes to anchor tag. if ( isset( $attributes['url'] ) ) { $html .= ' href="' . esc_url( block_core_navigation_link_maybe_urldecode( $attributes['url'] ) ) . '"'; } if ( $is_active ) { $html .= ' aria-current="page"'; } if ( isset( $attributes['opensInNewTab'] ) && true === $attributes['opensInNewTab'] ) { $html .= ' target="_blank" '; } if ( isset( $attributes['rel'] ) ) { $html .= ' rel="' . esc_attr( $attributes['rel'] ) . '"'; } elseif ( isset( $attributes['nofollow'] ) && $attributes['nofollow'] ) { $html .= ' rel="nofollow"'; } if ( isset( $attributes['title'] ) ) { $html .= ' title="' . esc_attr( $attributes['title'] ) . '"'; } // End appending HTML attributes to anchor tag. // Start anchor tag content. $html .= '>' . // Wrap title with span to isolate it from submenu icon. '<span class="wp-block-navigation-item__label">'; if ( isset( $attributes['label'] ) ) { $html .= wp_kses_post( $attributes['label'] ); } $html .= '</span>';Changelog
Introduced in 5.9.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/navigation-link.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.