0

when i click on the username in the adminbar it redirect me to the edit profile page of buddypress. My question is,how can i change it to user activity page? thank you very much.

  • you can do that with the action admin_bar_menu. look the function wp_admin_bar_my_account_menu – mmm Nov 6 '17 at 13:12
  • @mmm can you leave that as an answer instead of a comment with an example? Comments are for clarifying questions not answers – Tom J Nowell Nov 6 '17 at 13:58
  • thank you mmm but it's not clear. can you post the code that i have to insert in my function.php? – Luca Bellipanni Nov 6 '17 at 14:01
0

Create the following directory and file.
wp-content/mu-plugins/admin-bar-tweaks.php
Or, you can add this to your theme's functions.php file.

  • In the script below, remember to set $new_url to whatever you desire.

<?php // Requires PHP 5.4+.
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
    $new_url = 'http://example.com/custom/location';

    if ( $wp_admin_bar->get_node( 'my-account') ) {
        $wp_admin_bar->add_node( [
            'id'   => 'my-account',
            'href' => $new_url,
        ] );
    }
    if ( $wp_admin_bar->get_node( 'user-info') ) {
        $wp_admin_bar->add_node( [
            'id'   => 'user-info',
            'href' => $new_url,
        ] );
    }
    if ( $wp_admin_bar->get_node( 'edit-profile') ) {
        $wp_admin_bar->add_node( [
            'id'   => 'edit-profile',
            'href' => $new_url,
        ] );
    }
} );

A quick walk through this.

  • Attach to the admin_bar_menu hook.
  • Check if the my-account, user-info, and/or edit-profile nodes exist.
  • If each/any of them do, add them back in again, this time with a new URL. Note: When calling WP_Admin_Bar::add_node(), any properties you do not define will simply be set to whatever they were already. In this case, we are simply changing the href to $new_url.

To learn more, see: WP_Admin_Bar
See also: WP_Admin_Bar::add_node()
See also: default nodes in WordPress core.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.