Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How To Get Notification Count? (Code)?


  • chatty24
    Participant

    @chatty24

    Hey,

    I am trying to change the page title whenever there are notifications.

    If a user has more than 0 notifications then it should show, ‘You Have New Notifications’.

    I have tried out this code :

    $notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
        $count         = ! empty( $notifications ) ? count( $notifications ) : 0;
    
    if ( $count>0 ) {
      add_filter('wp_title','my_page_title',10,1);
    
    function my_page_title($title){
        $title='You Have New Notifications'; 
        return $title;
    }
      }

    But, it is not working. It is only working when I change the value of this code

    $count = ! empty( $notifications ) ? count( $notifications ) : 0;

    from 0 to 1,2 etc. Something like this,

    $count = ! empty( $notifications ) ? count( $notifications ) : 2;

    So, it is reading this end number as the number of notifications. I referred the notification code from here

    How can I make this code work?

    Thanks
    Have a nice day!

Viewing 3 replies - 26 through 28 (of 28 total)

  • danbp
    Participant

    @danbp

    That’s WP Toolbar user menu with BP user menu as subnav.
    https://codex.wordpress.org/Toolbar

    Googling for custom howdy menu will bring a lot of answers.


    AilyRoot
    Participant

    @ailyroot

    Hello

    thanks for this, but I am not looking for customize that tool bar, we want to move that part to somewhere else on to theme though


    danbp
    Participant

    @danbp

    You want to attach BP’s user menu to your custom howdy which is on the left, if i believe the screenshot.

    And that is explained on WP codex and probably somewhere on this forum.

Viewing 3 replies - 26 through 28 (of 28 total)
  • The topic ‘[Resolved] How To Get Notification Count? (Code)?’ is closed to new replies.
Skip to toolbar