• 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ddlg2007

    (@ddlg2007)

    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;
    }

    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 !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add login/register to nav menu? Help please’ is closed to new replies.