BuddyDev

Search

Replies

  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31220
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31218
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31166
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31147
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31136
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31130
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31127
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31118
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31087
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 94
    Ankit Raj on in reply to: [Resolved] activity #31051

    Ravi wrote:

    Hello Ankit,

    Above code provided just a sample code How to add a nav item using code. Please try the following code in your active theme “functions.php” file. It will add a menu with name “Visitors” and count. Please make sure you have enabled “Show a profile tab?” setting.

    
    /**
     * Add visitors link
     *
     * @param string   $items The HTML list content for the menu items.
     * @param stdClass $args  An object containing wp_nav_menu() arguments.
     *
     * @return string
     */
    function add_visitors_link( $items, $args ) {
    
        if ( ! is_user_logged_in() || ! function_exists( 'buddypress' ) || ! function_exists( 'visitors_get_profile_visit_count' ) ) {
            return $items;
        }
    
        $visitors_count = visitors_get_profile_visit_count( bp_loggedin_user_id() );
    
    	$visitors_tab_url = trailingslashit( bp_loggedin_user_domain() . 'visitors' );
    
    	$items .= sprintf( '<li><a href="%s">%s <span>%s</span></a></li>', esc_url( $visitors_tab_url ), __( 'Visitors', 'buddypress' ), $visitors_count );
    
    	return $items;
    }
    
    add_filter( 'wp_nav_menu_items', 'add_visitors_link', 10, 2 );