It is very easy to show unread message & announcement count in menu. There are numerous way to do this. Please follow any method bellow as you feel comfortable.
Adding PHP code:
This is recommended way but you need a little knowledge in PHP code editing.
Add following code in your theme’s (child theme’s if any) functions.php
add_filter( 'wp_nav_menu_items', 'fep_cus_add_menu_link', 10, 2 );
function fep_cus_add_menu_link( $items, $args ) {
if ( $args->theme_location == 'primary' ) {
$items .= '<li><a href="'. fep_query_url( 'messagebox' ) .'">' . sprintf(__('Message Box%s', 'front-end-pm'), fep_get_new_message_button() ) . '</a></li>';
}
return $items;
}
Change theme_location primary
text as you require. Or if you already added your menu just use require parts from here. main idea is to use fep_get_new_message_button()
to show unread message count. You can see this function in code of this plugin to get accepted arguments.
Adding Shortcode:
If you do not want to use PHP code change you can easily achieve same functionality using shortcode.
Go to your website back-end and add menu item. Make Navigation Label or Link Text of your menu as Messages[fep_shortcode_new_message_count]
(Change “Messages” with whatever you like but keep the shortcode).
Then add add_filter('wp_nav_menu_items', 'do_shortcode');
in your theme’s (Child theme’s if any) functions.php.
Please note: do_shortcode is a resource intensive function.
To know more about this shortcode and its accepted arguments see https://www.shamimsplugins.com/docs/front-end-pm/shortcode/fep_shortcode_new_message_count/
Adding class:
If you do not want to parse shortcode in your menu then you can follow this method.
Go to your website back-end and add menu item. Make Navigation Label or Link Text of your menu as Messages<span class="fep_unread_message_count"></span>
(Change “Messages” with whatever you like but keep span).
Then add following code in your theme’s (Child theme’s if you are using) functions.php.
add_filter('fep_filter_notification_call_on_ready', '__return_true');
add_action( 'wp_enqueue_scripts', function(){
wp_enqueue_script( 'fep-notification-script' );
});
Remember this will make an ajax request every time after page load to get unread message count.