Last active
January 14, 2025 14:33
-
-
Save KaineLabs/aa0c1080d84952c08f92f24225984dd9 to your computer and use it in GitHub Desktop.
Add Notifications And Messages Nav Menu Counts.
is there a shortcode for this function?
For Shortcodes:
<?php
/*
* Notification Icon with Counter Shortcode
* use [noticon]
*/
function yzc_notification_sc(){
$notifications_count = bp_notifications_get_unread_notification_count();
$not_icon = '<i class="fa fa-bell"></i><span class="yz-notification-count-header" style="color: #fff; text-align: center; background-color: #4990ee; border-radius: 100%;">'. $notifications_count . '</span>';
return $not_icon;
}
add_shortcode('noticon','yzc_notification_sc');
/*
* Message Icon with Counter Shortcode
* use [mesicon]
*/
function yzc_message_sc(){
$msgs_count = bp_get_total_unread_messages_count();
$mes_icon = '<i class="fa fa-envelope"></i><span class="yz-message-count-header" style="color: #fff; text-align: center; background-color: #4990ee; border-radius: 100%;">'. $msgs_count . '</span>';
return $mes_icon;
}
add_shortcode('mesicon','yzc_message_sc');
?>
Hello, If you want a conditional, so that when there is no notification, this can be used:
`/*
- Notification Icon with Counter Shortcode
- use [noticon]
*/
function yzc_notification_sc(){
$notifications_count = bp_notifications_get_unread_notification_count();
if ( $notifications_count > 0 ) {
$not_icon = '<a href="https://yourdomain.com/notifications/"><font color="red"><b>Avisos ('. $notifications_count .')</b></font></a>';
}
return $not_icon;
}
add_shortcode('noticon','yzc_notification_sc');`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What if I need it as a shortcode? [yz_notifications_count] [yz_messages_count] something like that.