• Resolved DivaVocals

    (@divavocals)


    I am using a piece of code in my theme’s function file to add a Log in/Log out link to my site’s primary nav menu. Currently it points to the WordPress default. Need some help modifying it so that it points to my new custom Login page. Hoping the author can help.. (pretty please)

    // in both cases, this code will add WP's built-in Login/Logout link to the last position in the menu
    // with acknowledgement to voodoopress.com
    // https://voodoopress.com/add-a-login-logout-link-to-only-one-specific-menu/
    //ADD LOGIN LINK TO PRIMARY MENU
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    
    function add_login_logout_link($items, $args) {
    	if( $args->theme_location == 'primary' ) {
    	$transmitredir = htmlspecialchars($_SERVER['REQUEST_URI']);
    	$loginoutlink = wp_loginout($transmitredir, false);
    	return $items . "<li> $loginoutlink </li>";
    	}
    	return $items;
    }

    https://www.ads-software.com/plugins/profile-builder/

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

    (@divavocals)

    Nevermind.. a little more research and I found this:

    // Add login and logout to default WordPress menu
    function add_login_logout_navitem($items, $args ) {
        if( $args->theme_location == 'primary' ) {
            if ( !(is_user_logged_in()) ) {
                $login_item = '<li id="menu-item-login" class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/login">Log in</a></li>';
            }
            else {
                $login_item = '<li id="menu-item-logout" class="menu-item menu-item-type-post_type menu-item-object-page">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
            }
            $items .= $login_item;
        }
        return $items;
    }
    
    add_filter('wp_nav_menu_items', 'add_login_logout_navitem', 10, 2);

    (source: https://rezzz.com/add-login-and-logout-to-your-wordpress-menu/)

    Works like a charm with this plugin.. The code I posted before works best if you’re NOT using this plugin..

    @divavocals – thanks for referring to my post (I know I’m like a year late ;)) – however I do appreciate it very much.

    I wanted to point out that the link you have here includes the “)” which then results in a 404 on my website.

    So I just wanted to come here and provide the proper link since I’ve seen a few 404s popping up from this page.

    https://rezzz.com/add-login-and-logout-to-your-wordpress-menu/

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Point my menu Log in/Log out link to my custom pages’ is closed to new replies.