Login / Logout Menu Item

PHOTO EMBED

Thu Feb 17 2022 08:17:10 GMT+0000 (Coordinated Universal Time)

Saved by @Prowhiz #php

add_filter( 'wp_nav_menu_top-menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
    if (is_user_logged_in()) {
        $items .= '<li class="menu-item"><a href="'. wp_logout_url() .'">Log Out</a></li>';
    }
    elseif (!is_user_logged_in()) {
        $items .= '<li class="menu-item"><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
    }
    return $items;
}
content_copyCOPY

I often add a Login / Logout menu item for convenience. Menu locations are often declared in the theme, but since Oxygen doesn’t use a theme I had to modify my regular snippet to work without a declared menu location. I found a description of how to do this here.

https://www.webtng.com/code-snippets-used-when-creating-an-oxygen-site/