Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#31586 closed enhancement (worksforme)

Admin Bar: site-name link for is_admin() in admin-bar.php

Reported by: landwire's profile landwire Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1.1
Component: Toolbar Keywords:
Focuses: ui Cc:

Description

Hi there,

at the moment the site-name link in the admin bar point to the admin_url(). Would it be possible to put a filter in to override that? As the first item in the dropdown menu is the dashboard and links exactly to the same place!
I am quite happy to link to the home_url for all users, also admins. Somehow it feels consistent, as I also use the adminbar on the frontend. Anyway, just a thought.

This is the code as is in admin-bar.php, just so you know what I am talking about:

$wp_admin_bar->add_menu( array(
		'id'    => 'site-name',
		'title' => $title,
		'href'  => is_admin() ? home_url( '/' ) : admin_url(),
	) );

Thanks,
Sascha

Change History (2)

#1 @ocean90
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Hello Sascha,

you can do this already with the following code:

function trac_replace_site_name_link_in_toolbar( $wp_admin_bar ) {
	if ( ! $wp_admin_bar->get_node( 'site-name' ) ) {
		return;
	}

	$menu = array( 'id' => 'site-name', 'href' => home_url( '/' ) );
	$wp_admin_bar->add_menu( $menu );
}
add_action( 'admin_bar_menu', 'trac_replace_site_name_link_in_toolbar', 35 );

There is no need for a new filter here.

I am quite happy to link to the home_url for all users, also admins.

Hint: is_admin() exists to check whether the current request is for an administrative interface page, and not if the user is an administrator.

#2 @landwire
11 years ago

Oh, bummer! Thanks! I just looked at my functions file where I had similar code to yours, but by accident I had add_filter, instead of add_action. I just assumed it does not work. Must be getting to late. And thanks for the is_admin() hint - way too late now :-)

Thanks for the quick reply btw.

Note: See TracTickets for help on using tickets.