wp_admin_bar_wp_menu() WordPress Function

The wp_admin_bar_wp_menu() function is used to display a WordPress menu in the admin bar. The function takes two arguments: the menu ID and the menu name. The function can be used to create a WordPress menu in the admin bar for a specific purpose or to display an existing WordPress menu.

wp_admin_bar_wp_menu( WP_Admin_Bar $wp_admin_bar ) #

Adds the WordPress logo menu.


Parameters

$wp_admin_bar

(WP_Admin_Bar)(Required)The WP_Admin_Bar instance.


Top ↑

Source

File: wp-includes/admin-bar.php

function wp_admin_bar_wp_menu( $wp_admin_bar ) {
	if ( current_user_can( 'read' ) ) {
		$about_url = self_admin_url( 'about.php' );
	} elseif ( is_multisite() ) {
		$about_url = get_dashboard_url( get_current_user_id(), 'about.php' );
	} else {
		$about_url = false;
	}

	$wp_logo_menu_args = array(
		'id'    => 'wp-logo',
		'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>',
		'href'  => $about_url,
	);

	// Set tabindex="0" to make sub menus accessible when no URL is available.
	if ( ! $about_url ) {
		$wp_logo_menu_args['meta'] = array(
			'tabindex' => 0,
		);
	}

	$wp_admin_bar->add_node( $wp_logo_menu_args );

	if ( $about_url ) {
		// Add "About WordPress" link.
		$wp_admin_bar->add_node(
			array(
				'parent' => 'wp-logo',
				'id'     => 'about',
				'title'  => __( 'About WordPress' ),
				'href'   => $about_url,
			)
		);
	}

	// Add WordPress.org link.
	$wp_admin_bar->add_node(
		array(
			'parent' => 'wp-logo-external',
			'id'     => 'wporg',
			'title'  => __( 'WordPress.org' ),
			'href'   => __( 'https://wordpress.org/' ),
		)
	);

	// Add documentation link.
	$wp_admin_bar->add_node(
		array(
			'parent' => 'wp-logo-external',
			'id'     => 'documentation',
			'title'  => __( 'Documentation' ),
			'href'   => __( 'https://wordpress.org/support/' ),
		)
	);

	// Add forums link.
	$wp_admin_bar->add_node(
		array(
			'parent' => 'wp-logo-external',
			'id'     => 'support-forums',
			'title'  => __( 'Support' ),
			'href'   => __( 'https://wordpress.org/support/forums/' ),
		)
	);

	// Add feedback link.
	$wp_admin_bar->add_node(
		array(
			'parent' => 'wp-logo-external',
			'id'     => 'feedback',
			'title'  => __( 'Feedback' ),
			'href'   => __( 'https://wordpress.org/support/forum/requests-and-feedback' ),
		)
	);
}


Top ↑

Changelog

Changelog
VersionDescription
3.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.