Do you want to add a login/logout in your primary navigation menu? You can do it using some tweaks in Canvas.

Prerequisite(s)
Canvas Child Theme with style.css and functions.php files

Step 1 Login to WordPress control panel

Step 2 Go to Appearance > Editor

Step 3 Click functions.php to edit


Step 4 In the functions.php file, enter the codes below

add_filter( ‘wp_nav_menu_items’, ‘add_loginout_link’, 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == ‘primary-menu’) {
$items .= ‘<li><a href=”‘. wp_logout_url() .'”>Log Out</a></li>’;
}
elseif (!is_user_logged_in() && $args->theme_location == ‘primary-menu’) {
$items .= ‘<li><a href=”‘. site_url(‘wp-login.php’) .'”>Log In</a></li>’;
}
return $items;
}


Step 4 Click Update File button

Step 5 Go to your online site and notice the login/logout in the primary menu


Here is a video tutorial on how add a login/logout feature in the primary navigation menu

Leave a Reply

Your email address will not be published. Required fields are marked *