Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to get the Buddypress notification bubble to appear in one of my two navigation bars. I was given this code to place in my functions.php which does everything, except it displays in both menus rather than the specific one I require.

My menu's area "top" and "primary" I want the notification to only appear in top. Can anyone tell me how to do this? I've tried various ways from snippets of code I've seen online, mainly around adding a search bar to a specific menu, and it either hides from both, or makes no changes.

if ( is_user_logged_in() ) {    add_filter('wp_nav_menu_items','add_notification_to_custom_menu', 2, 2);
function add_notification_to_custom_menu( $items, $args ) {
$notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id() );
$count         = ! empty( $notifications ) ? count( $notifications ) : 0;
if ($count > 0 ) {
    $alert = 'alert';
    $pending = 'pending-count';
} else {
    $alert = 'no-alert';
    $pending = 'count';
}
return $items."<li id='menu-bp-notifications' class='menupop'><a   href='".bp_loggedin_user_domain()."notifications/' class='ab-item'><span id='ab-pending-notifications' class='" . $pending . " " . $alert . "'>".$count."</a></li>";

return $items;
}
}
share|improve this question

1 Answer 1

I'm not much help here, but I can guess the solution:

Both menus will have wp_nav_menu_items so thats why you are returning your function for both of them.

function add_notification_to_custom_menu( $items, $args ) {
   var_dump($items); // we dont need this, but anyways
   var_dump($args); // here should be a name of your menu
}

rewrite your function like this to see if $args contains something useful information, like menu name or ID.. everything will do

Then we can write a condition

if($args['menu'] == 'top') {
   // do it
}

hope this works

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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