Title: WP_Admin_Bar::_render_item
Published: April 25, 2014
Last modified: April 28, 2025

---

# WP_Admin_Bar::_render_item( object $node )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#wp--skip-link--target)

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#parameters)󠁿

 `$node`objectrequired

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#source)󠁿

    ```php
    final protected function _render_item( $node ) {
    	if ( 'item' !== $node->type ) {
    		return;
    	}

    	$is_parent             = ! empty( $node->children );
    	$has_link              = ! empty( $node->href );
    	$is_root_top_item      = 'root-default' === $node->parent;
    	$is_top_secondary_item = 'top-secondary' === $node->parent;

    	// Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y.
    	$tabindex         = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';
    	$aria_attributes  = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : '';
    	$aria_attributes .= ' role="menuitem"';

    	$menuclass = '';
    	$arrow     = '';

    	if ( $is_parent ) {
    		$menuclass        = 'menupop ';
    		$aria_attributes .= ' aria-expanded="false"';
    	}

    	if ( ! empty( $node->meta['class'] ) ) {
    		$menuclass .= $node->meta['class'];
    	}

    	// Print the arrow icon for the menu children with children.
    	if ( ! $is_root_top_item && ! $is_top_secondary_item && $is_parent ) {
    		$arrow = '<span class="wp-admin-bar-arrow" aria-hidden="true"></span>';
    	}

    	if ( $menuclass ) {
    		$menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"';
    	}

    	echo "<li role='group' id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$menuclass>";

    	if ( $has_link ) {
    		$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
    		echo "<a class='ab-item'$aria_attributes href='" . esc_url( $node->href ) . "'";
    	} else {
    		$attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
    		echo '<div class="ab-item ab-empty-item"' . $aria_attributes;
    	}

    	foreach ( $attributes as $attribute ) {
    		if ( empty( $node->meta[ $attribute ] ) ) {
    			continue;
    		}

    		if ( 'onclick' === $attribute ) {
    			echo " $attribute='" . esc_js( $node->meta[ $attribute ] ) . "'";
    		} else {
    			echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'";
    		}
    	}

    	echo ">{$arrow}{$node->title}";

    	if ( $has_link ) {
    		echo '</a>';
    	} else {
    		echo '</div>';
    	}

    	if ( $is_parent ) {
    		echo '<div class="ab-sub-wrapper">';
    		foreach ( $node->children as $group ) {
    			if ( empty( $node->meta['menu_title'] ) ) {
    				$this->_render_group( $group, false );
    			} else {
    				$this->_render_group( $group, $node->meta['menu_title'] );
    			}
    		}
    		echo '</div>';
    	}

    	if ( ! empty( $node->meta['html'] ) ) {
    		echo $node->meta['html'];
    	}

    	echo '</li>';
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-admin-bar.php#L542)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-admin-bar.php#L542-L625)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#related)󠁿

| Uses | Description | 
| [esc_js()](https://developer.wordpress.org/reference/functions/esc_js/)`wp-includes/formatting.php` |

Escapes single quotes, `"`, , `&amp;`, and fixes line endings.

  | 
| [WP_Admin_Bar::_render_group()](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_group/)`wp-includes/class-wp-admin-bar.php` |  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#)

| Used by | Description | 
| [WP_Admin_Bar::_render_group()](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_group/)`wp-includes/class-wp-admin-bar.php` |  | 
| [WP_Admin_Bar::recursive_render()](https://developer.wordpress.org/reference/classes/wp_admin_bar/recursive_render/)`wp-includes/class-wp-admin-bar.php` |

Renders toolbar items recursively.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render_item/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_admin_bar%2F_render_item%2F)
before being able to contribute a note or feedback.