WordPress shows registration link for non logged users

I have a WordPress site and I want to add a registration link for visitors.

So, I added a menu item called ‘REGISTER’ with the following link:

http://mywebsite.com/wp-login.php?action=register

The problem is that this link opens the registration form for both users and visitors and I want to show it only to visitors.

Solutions Collecting From Web of "WordPress shows registration link for non logged users"

Add your registration or log in link inside of the is_user_logged_in() function. So If the current user not logged on your site then this function will show the login page for them and that user If not registered he/she must have to register in order to log in to your site.

Code example:

<?php
if( !is_user_logged_in() ) {
  <a href="<?php echo wp_login_url(); ?>">Log in / Register</a>
}

You can use wp_nav_menu_items filter to conditionally add a menu item. Add this code to your theme’s functions.php:

function wpse_custom_menu_item( $items, $args ) {
    if( !is_user_logged_in() && $args->theme_location == 'primary-menu' ) {
        $items .= '<li><a href="http://mywebsite.com/wp-login.php?action=register">Register</a></li>';
    }
    return $items;
}
add_filter( 'wp_nav_menu_items', 'wpse_custom_menu_item', 10, 2 );

i fixed the problem with Nav Menu Roles plugin

I added the registration link to the menu and with the plugin and i set it to only logged out users

This way it won’t show to logged users