I know WP admin bar has the message icon. But I have made

I know WP admin bar has the message icon. But I have made that bar inactive for my users so is it possible to have that message icon on the main or secondary navigation? Is there a shortcode for this?

  • Sajid

    Hi @Ghulam Rasool

    Hope you are doing good and welcome back :slight_smile:

    I am afraid their is not possible out of the box. But I wrote a quick function to inject link showing number of messages and link to inbox, in your main navigation.

    Add it in functions.php file of your child theme or use mu-plugins.

    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
    function add_loginout_link( $items, $args ) {
    	$unread = MM_Conversation_Model::count_unread();
    
        $items .= '<li><a href="'.get_permalink(mmg()->setting()->inbox_page).'"><i class="fa fa-envelope"></i>&nbsp;<span>' . $unread . '</span></a></li>';
            return $items;
    }

    Hope it helps :slight_smile:

    Cheers, Sajid

  • Sajid

    Hi @Ghulam Rasool

    Hope you are doing good today :slight_smile:

    I updated the code for you.

    This code will add icon at first in main menu if user is logged in and plugin is active.

    if(class_exists( 'MM_Conversation_Model' )){
    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 1, 2 );
    	function add_loginout_link( $items, $args ) {
    
    		//Return if user not logged in
    		if(!is_user_logged_in()) return $items;
    
    		$unread = MM_Conversation_Model::count_unread();
    
    		$ritems = '<li><a href="'.get_permalink(mmg()->setting()->inbox_page).'"><i class="fa fa-envelope"></i>&nbsp;<span>' . $unread . '</span></a></li>'.$items;
    
    		return $ritems;
    	}
    }

    Add this code in functions.php file of your child theme or use mu-plugins.

    if(class_exists( 'MM_Conversation_Model' )){
     	function wpmu_message_notif_icon() {
    
    		//Return if user not logged in
    		if(!is_user_logged_in()) return;
    
    		$unread = MM_Conversation_Model::count_unread();
    
    		$ritems = '<a href="'.get_permalink(mmg()->setting()->inbox_page).'"><i class="fa fa-envelope"></i>&nbsp;<span>' . $unread . '</span></a>';
    				return $ritems;
    	}
    }

    Now to show anywhere on your website use following code.
    <?php echo wpmu_message_notif_icon();?>

    Hope it helps :slight_smile:

    Cheers, Sajid