Admin & Dashboard PHP Beginner

Add Quick Links to the Admin Bar

Add a "Quick links" menu to the admin bar with shortcuts to screens you open often, like Permalinks and Site Health.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 26 lines
add_action( 'admin_bar_menu', function ( WP_Admin_Bar $bar ): void {
	if ( ! current_user_can( 'manage_options' ) ) {
		return;
	}

	$bar->add_node( [ 'id' => 'nahnu-quick', 'title' => 'Quick links', 'href' => false ] );

	$links = [
		'Permalinks'  => admin_url( 'options-permalink.php' ),
		'Site Health' => admin_url( 'site-health.php' ),
		'Menus'       => admin_url( 'nav-menus.php' ),
		'Plugins'     => admin_url( 'plugins.php' ),
	];
	if ( class_exists( 'WooCommerce' ) ) {
		$links['WooCommerce status'] = admin_url( 'admin.php?page=wc-status' );
	}

	foreach ( $links as $title => $href ) {
		$bar->add_node( [
			'parent' => 'nahnu-quick',
			'id'     => 'nahnu-quick-' . sanitize_title( $title ),
			'title'  => esc_html( $title ),
			'href'   => esc_url( $href ),
		] );
	}
}, 100 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

If you keep opening the same few admin screens, a shortcut saves clicks. This snippet adds a “Quick links” dropdown to the admin bar, on the front end and in wp-admin.

How it works

On admin_bar_menu, the snippet adds a parent item, then a child item for each link. admin_url() builds the addresses so they work on any domain. A WooCommerce status link is added only when WooCommerce is active.

Things to watch

  • Only administrators see the menu.
  • Edit the $links array to add your own, such as a plugin’s settings page.

How to test it

Hover over “Quick links” in the admin bar. The dropdown should list your shortcuts.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only