WordPress.org

Ready to get started?Download WordPress

Forums

Add login/register to nav menu? Help please (3 posts)

  1. ddlg2007
    Member
    Posted 3 years ago #

    Hi guys I to implement a register/login in the menu. I edited functions.php and I added the following code:

    add_action('wp_head', 'cg_loves_ipad');
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    function add_login_logout_link($items, $args) {
    
            ob_start();
            wp_loginout('index.php');
            $loginoutlink = ob_get_contents();
            ob_end_clean();
    
            $items .= '<li>'. $loginoutlink .'</li>';
    
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_register_link', 10, 2);
    function add_register_link($items, $args) {
    
            ob_start();
            wp_register('');
            $registerlink = ob_get_contents();
            ob_end_clean();
    
            $items .= '<li>'. $registerlink .'</li>';
    
        return $items;
    }

    The problem is that all logged in users appear as the site administrator instead of putting his nick. Someone help me modify the code? Do not know much about php.

  2. ddlg2007
    Member
    Posted 3 years ago #

    Please some one can help me? I make a new modification for redirect to the same page:

    function add_login_logout_link($items, $args) {
    
            ob_start();
            wp_loginout( $_SERVER['REQUEST_URI'] );
            $loginoutlink = ob_get_contents();
            ob_end_clean();
    
            $items .= '<li>'. $loginoutlink .'</li>';
    
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_register_link', 10, 2);
    function add_register_link($items, $args) {
    
            ob_start();
            wp_register('');
            $registerlink = ob_get_contents();
            ob_end_clean();
    
            $items .= '<li>'. $registerlink .'</li>';
    
        return $items;
    }
  3. venug
    Member
    Posted 3 years ago #

    I think the experts at WordPress.stackexchange.com can help you with this. Ask it there and please let me know the link of question after you post

    Thanks !

Topic Closed

This topic has been closed to new replies.

About this Topic