Add Login/Logout item to top menu bar in WordPress

Add this code to your theme’s functions.php file.

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();
        if ($args->theme_location == 'top')
                $items .= '<li>'. $loginoutlink . '</li>';
    return $items;
}

 

Sharing...

Leave a Reply