Skip to main content

better_messages_update_unread

REQUIREMENTS

To be able to implement this guide, you need to learn how to use JS snippets at your website.

One of guides: https://dev.to/david_woolf/how-to-get-started-with-wordpress-hooks-in-javascript-400o

Compatibility
This hook compatible with Better Messages 2.3.12 or higher

Sometimes you need to create custom unread messages counter at your website.

This is example of code snippet to make counter display messages count dynamically:

<script type="text/javascript">
wp.hooks.addAction('better_messages_update_unread', 'custom_action', function( unread ){
// unread variable contains count of unread conversations
var messages_count = jQuery('.header-notifications.user-messages span');

if( unread > 0 ){
messages_count.text(unread).attr('class', 'count');
} else {
messages_count.text(unread).attr('class', 'no-alert');
}
});
</script>