We may need to customize the gravatar or provide the custom link to the profile page in the the user action drop down under the user name (right top corner) in admin bar, In order to do the customization we can use the wp_before_admin_bar_render action hook as shown below.
add_action( 'wp_before_admin_bar_render', 'custom_remove_my_account' );
if (!function_exists('custom_remove_my_account')) {
function custom_remove_my_account() {
global $wp_admin_bar;
$wp_admin_bar->remove_node('user-actions'); /*Removed the default user action dropdown*/
custom_admin_bar_my_account_menu($wp_admin_bar);
}
}
/**
custom_admin_bar_my_account_menu method alters the user action dropdown
*/
if (!function_exists('custom_admin_bar_my_account_menu')) {
function custom_admin_bar_my_account_menu( $wp_admin_bar ) {
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url = get_permalink( 6 ); /*Here i just provided the custom page link as profile page*/
if ( ! $user_id )
return;
$wp_admin_bar->add_group( array(
'parent' => 'my-account',
'id' => 'user-actions',
)
);
$user_info = get_avatar( $user_id, 64 );
$user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
if ( $current_user->display_name !== $current_user->user_login )
$user_info .= "<span class='username'>{$current_user->user_login}</span>";
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'user-info',
'title' => $user_info,
'href' => $profile_url,
'meta' => array(
'tabindex' => -1,
),
)
);
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'edit-profile',
'title' => __( 'Edit My Profile' ),
'href' => $profile_url,
)
);
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'logout',
'title' => __( 'Log Out' ),
'href' => wp_logout_url(home_url()),
)
);
}
}
Just paste the abovecode in either plugin files or in the functions.php ( theme file ).
add_action( 'wp_before_admin_bar_render', 'custom_remove_my_account' );
if (!function_exists('custom_remove_my_account')) {
function custom_remove_my_account() {
global $wp_admin_bar;
$wp_admin_bar->remove_node('user-actions'); /*Removed the default user action dropdown*/
custom_admin_bar_my_account_menu($wp_admin_bar);
}
}
/**
custom_admin_bar_my_account_menu method alters the user action dropdown
*/
if (!function_exists('custom_admin_bar_my_account_menu')) {
function custom_admin_bar_my_account_menu( $wp_admin_bar ) {
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url = get_permalink( 6 ); /*Here i just provided the custom page link as profile page*/
if ( ! $user_id )
return;
$wp_admin_bar->add_group( array(
'parent' => 'my-account',
'id' => 'user-actions',
)
);
$user_info = get_avatar( $user_id, 64 );
$user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
if ( $current_user->display_name !== $current_user->user_login )
$user_info .= "<span class='username'>{$current_user->user_login}</span>";
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'user-info',
'title' => $user_info,
'href' => $profile_url,
'meta' => array(
'tabindex' => -1,
),
)
);
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'edit-profile',
'title' => __( 'Edit My Profile' ),
'href' => $profile_url,
)
);
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'logout',
'title' => __( 'Log Out' ),
'href' => wp_logout_url(home_url()),
)
);
}
}
Just paste the abovecode in either plugin files or in the functions.php ( theme file ).
No comments:
Post a Comment