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:


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

3 Answers 3


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:

if( !is_user_logged_in() ) {
  <a href="<?php echo wp_login_url(); ?>">Log in / Register</a>
  • i know but i want to add this code in the whole wordpress not just a specific page Oct 9, 2017 at 13:48

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.