Changing adminbar site-name url
-
Hi everybody,
When you are in the dashboard and click on the site name (in the left corner of the adminbar) you are normally redirected to the site url (homepage), which in my case is pretitude.com
How can change that url, so that the user goes to another page, for example pretitude.com/activity/ ?
Why I want to do that:
Because my homepage is the register page. This page normally can’t be seen by a logged in user, but it is cached by the browser and users see it and think they are logged out (while they are not).
Any idea?
Here is a screenshot
-
You could customize the adminbar completely, using this snippet. I’m hiding the W menu, but you could probably hid the Sites menu and then add your own dropdown with the requisite links.
http://www.wpbeginner.com/plugins/how-to-add-edit-re-order-or-hide-wordpress-admin-menus/
/** * Adds custom "Home" menu to WP Adminbar. * * Also removes the "WP logo" menu. * * @param object $wp_admin_bar The WP Admin Bar object */ public function add_custom_parent_menu( $wp_admin_bar ) { /** * Removing the "W" menu */ $wp_admin_bar->remove_menu( 'wp-logo' ); /** * Create a "Home" menu. * * First, just create the parent menu item. */ $wp_admin_bar->add_menu( array( 'id' => 'commonlinks', 'parent' => '0', //puts it on the left-hand side 'title' => 'Home', 'href' => ('INSERT LINK HERE') ) ); /** * Add submenu items to "Home" menu. */ // Only show the following for logged-in users if ( current_user_can( 'read' ) ) { // Support link $wp_admin_bar->add_menu( array( 'id' => 'support', 'parent' => 'commonlinks', 'title' => 'Support', 'href' => ('INSERT LINK HERE') ) ); // Blog request form $wp_admin_bar->add_menu( array( 'id' => 'blogrequest', 'parent' => 'commonlinks', 'title' => 'Stuff', 'href' => ('INSERT LINK HERE' ) ) ); // Developers blog $wp_admin_bar->add_menu( array( 'id' => 'developments', 'parent' => 'commonlinks', 'title' => 'Developments', 'href' => ('INSERT LINK HERE' ) ) ); } }
Thanks @mrjarbenne for your response.
Unfortunately your code doesn’t work for me; it makes my dashboard a blank page. I already tested the concept “remove the original Home in order to add my own customized Home” with snippets I found on the internet, but this solution is not compatible with responsiveness. All the links you add on the adminbar, will disappear when you see the site on a small screen, for example on a smartphone.
So the problem remains and I think the only solution is to change the URL of the original Home
Apologies. This is better. Missed a few steps:
//Customize Adminbar add_action('admin_bar_menu', 'customize_admin_bar', 11 ); function customize_admin_bar( $wp_admin_bar ) { //Remove the "W" menu $wp_admin_bar->remove_menu( 'wp-logo' ); /** * Create a "Home" menu. * * First, just create the parent menu item. */ $wp_admin_bar->add_menu( array( 'id' => 'commonlinks', 'parent' => '0', //puts it on the left-hand side 'title' => 'Home', 'href' => ('INSERT LINK HERE') ) ); /** * Add submenu items to "Home" menu. */ // Only show the following for logged-in users if ( current_user_can( 'read' ) ) { // Support link $wp_admin_bar->add_menu( array( 'id' => 'support', 'parent' => 'commonlinks', 'title' => 'Support', 'href' => ('INSERT LINK HERE') ) ); // Blog request form $wp_admin_bar->add_menu( array( 'id' => 'blogrequest', 'parent' => 'commonlinks', 'title' => 'Stuff', 'href' => ('INSERT LINK HERE' ) ) ); // Developers blog $wp_admin_bar->add_menu( array( 'id' => 'developments', 'parent' => 'commonlinks', 'title' => 'Developments', 'href' => ('INSERT LINK HERE' ) ) ); } }
In order to force that menu to appear on mobile, you need to tweak the CSS with something like this:
#wpadminbar li#wp-admin-bar-commonlinks { display: block; }
The new code adds indeed a Home. Screenshot
But this Home still doesn’t show on smaller screns. Screenshot
I have added the css, but it has no effect. As I see only icons are shown on small screens. Unfortunately…
Finally I could resolve the problem after reading this article
This developer suggests creating a plugin. The result is a link with a dashicon but it is not responsive. To make it responsive (show on mobile), I added in the css file of the plugin a snippet I fould elsewhere:
@media screen and (max-width: 782px) { #wpadminbar li#wp-admin-bar-XXX { display: block; } }
Replace XXX with your id
You could completely customize the Admin-bar. This snippet should help, put in either the functions.php file of your theme, or in the bp-custom.php file. It should give you a good idea of what is possible. I’m hiding the W menu. You could probably hide the Site dropdown altogether and then craft your own dropdown with links to different items. Particularly if this is a single install of BP, and not a Network/Multisite install, there really isn’t any reason for your users to see the Site dropdown:
/** * Adds custom "Home" menu to WP Adminbar. * * Also removes the "WP logo" menu. * * @param object $wp_admin_bar The WP Admin Bar object */ public function add_custom_parent_menu( $wp_admin_bar ) { /** * Removing the "W" menu */ $wp_admin_bar->remove_menu( 'wp-logo' ); /** * Create a "Home" menu. * * First, just create the parent menu item. */ $wp_admin_bar->add_menu( array( 'id' => 'commonlinks', 'parent' => '0', //puts it on the left-hand side 'title' => 'Home', 'href' => ('http://domain.com/activity') ) ); /** * Add submenu items to "Home" menu. */ // Only show the following for logged-in users if ( current_user_can( 'read' ) ) { // Support link $wp_admin_bar->add_menu( array( 'id' => 'support', 'parent' => 'commonlinks', 'title' => 'Support', 'href' => ('http://domain.com/support') ) ); // Blog request form $wp_admin_bar->add_menu( array( 'id' => 'blogrequest', 'parent' => 'commonlinks', 'title' => 'Feedback', 'href' => ('http://domain.com/feedback' ) ) ); // Developers blog $wp_admin_bar->add_menu( array( 'id' => 'developments', 'parent' => 'commonlinks', 'title' => 'Developments', 'href' => ('http://domain.com/developments' ) ) ); } }
Sorry, after resolving the problem as I mentionned above, I completely forgot this thread.
Thank you very much for your code. I saved it in case it is useful in the future.
Have a nice day!
- You must be logged in to reply to this topic.