How to Display unread message count for users

I know that there’s a shortcode that dose shows how many unread messages a user has
but how can I display this in the account menu
shortcodes don’t work in functions :frowning:
Are there any hooks that can function the same as this shortcode?

[better_messages_unread_counter hide_when_no_messages="1" preserve_space="1"]

I wanted to solve this by adding the shortcode to the function and using the do_shortcode

add_filter(
    'hivepress/v1/menus/user_account',
    function( $menu ) {

        $unread_messages_shortcode = '[better_messages_unread_counter hide_when_no_messages="1" preserve_space="1"]';

 
        $unread_messages_counter = do_shortcode($unread_messages_shortcode);

   
        $chat_label = 'Messges ' . $unread_messages_counter;

  
        $menu['items']['chat'] = [
            'label'  => $chat_label,
            'url'    => 'https://my-site.com/chat',
            '_order' => 20,
        ];

        return $menu;
    }
);

Related posts

Hi,

Unfortunately, we cannot provide information about third-party plugins, so I recommend contacting its developer to find out how to get the count. Regarding the count display, if the menu item of this plugin is already added to the account using the account menu hook, you can pass this to the meta parameter in the item, and this count will be displayed in a red circle.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.