# BuddyPress: Unread Notifications Shortcode

> Adds a [wpide_bp_notifications] shortcode that shows a bell link with the member's unread BuddyPress notification count, for headers and menus built with blocks.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: buddypress, notifications, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/buddypress-notification-count-shortcode/

## Code

```php
if ( ! function_exists( 'buddypress' ) ) {
    return;
}

add_shortcode( 'wpide_bp_notifications', function () {
    $user_id = bp_loggedin_user_id();

    if ( ! $user_id || ! bp_is_active( 'notifications' ) ) {
        return '';
    }

    $count = (int) bp_notifications_get_unread_notification_count( $user_id );
    $label = sprintf( _n( '%d unread notification', '%d unread notifications', $count ), $count );

    return sprintf(
        '<a class="wpide-bp-bell" href="%1$s" aria-label="%2$s"><span aria-hidden="true">&#128276;</span>%3$s</a>',
        esc_url( bp_get_notifications_permalink( $user_id ) ),
        esc_attr( $label ),
        $count ? '<span class="wpide-bp-bell__count" aria-hidden="true" style="display:inline-block;min-width:1.4em;margin-left:.25em;padding:0 .35em;border-radius:999px;background:#d63638;color:#fff;font-size:.75em;text-align:center">' . esc_html( number_format_i18n( $count ) ) . '</span>' : ''
    );
} );
```

## Notes

Shows nothing to visitors. Style the badge with .wpide-bp-bell__count.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "BuddyPress: Unread Notifications Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
