Add Buddypress Notifications to theme

I just wanted to share some information I got today in Live Chat for those users looking to move away from the wordpress toolbar.

I’m setting up my community to not show the toolbar to anyone but the admin, so I needed a way to show buddypress notifications as they happen.

@kasia Swiderska helped me today find the solution and I wanted to share it with community.

Add the following to the functions.php of your theme:

function cg_current_user_notification_count() {
$notifications = bp_core_get_notifications_for_user(bp_loggedin_user_id(), 'object');
$count = !empty($notifications) ? count($notifications) : 0;

echo $count;

After you add the above, just add this code to where you want to display the notification:

<p><a href="<?php echo bp_core_get_user_domain(bp_loggedin_user_id()); ?>"><?php cg_current_user_notification_count(); ?> - Notifications</a></p>

Thats it! It worked great for my site and I id some customization work to make it look pretty. (see image below)

Hope this helps anyone wanting to add BP Notifications to your theme without a plugin.

Link to Original Credits: