Title: Register link
Last modified: August 22, 2016

---

# Register link

 *  Resolved [sillydwa](https://wordpress.org/support/users/sillydwa/)
 * (@sillydwa)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/)
 * I am trying to get all my links on my primary menu bar.
 * I have log in and log out links already on the primary menu by adding
 *     ```
       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;
       }
       ```
   
 * to the functions file in my site.
 * What I am wondering is there a way for me to add the register link as well but
   have it disappear when they log in?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930613)
 * Try this (I’ve modified/enhanced your code a little):
 *     ```
       add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
       function add_loginout_link( $items, $args ) {
   
       	if($args->theme_location == 'primary-menu') {
       		if(is_user_logged_in()) {
       			$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
       		}
       		else {
       			$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
       			$items .= '<li><a href="'. site_url('wp-login.php?action=register') .'">Register</a></li>';
       		}
       	}
           return $items;
       }
       ```
   
 *  Thread Starter [sillydwa](https://wordpress.org/support/users/sillydwa/)
 * (@sillydwa)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930617)
 * I added the code as follows
 *     ```
       add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
       function add_loginout_link( $items, $args ) {
   
       	if($args->theme_location == 'primary-menu') {
       		if(is_user_logged_in()) {
       			$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
       		}
       		else {
       			$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
       			$items .= '<li><a href="'. site_url('wp-login.php?action=register') .'">Register</a></li>';
       		}
       	}
           return $items;
       }
       ```
   
 * it has made the login / Logout Link disappear and all that is shown is the Register
   link.
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930624)
 * Weird?!
 * Let’s go back to your original code, then:
 *     ```
       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>';
               $items .= '<li><a href="'. site_url('wp-login.php?action=register') .'">Register</a></li>';
           }
           return $items;
       }
       ```
   
 *  Thread Starter [sillydwa](https://wordpress.org/support/users/sillydwa/)
 * (@sillydwa)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930625)
 * ok so this particular code is working for the login and logout
 *     ```
       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();
               $items .= '<li>'. $loginoutlink .'</li>';
           return $items;
       }
       ```
   
 * how would i modify this to show register if the user is logged out and not if
   the user is logged in.
 * I made a boo boo and posted code from an old site originally I apologize for 
   the confusion
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930639)
 * Hmm… I don’t like the `ob_start()` method…
 * One sec…
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930646)
 * Okay, try this one:
 *     ```
       add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
       function add_loginout_link( $items, $args ) {
   
       	if($args->theme_location == 'primary') {
       		if (is_user_logged_in()) {
       			$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
       		}
       		else {
       			$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
       			$items .= '<li><a href="'. site_url('wp-login.php?action=register') .'">Register</a></li>';
       		}
       	}
           return $items;
       }
       ```
   
 * The problem was the `primary-menu` should be just `primary`.
 *  Thread Starter [sillydwa](https://wordpress.org/support/users/sillydwa/)
 * (@sillydwa)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930648)
 * Absolutely Beautiful!!! That worked!!! You my friend are awesome 🙂 thanks for
   the quick help!!!
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930657)
 * Lol… you’re very welcome 🙂
 * Have fun!!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Register link’ is closed to new replies.

## Tags

 * [login](https://wordpress.org/support/topic-tag/login/)
 * [Logout](https://wordpress.org/support/topic-tag/logout/)
 * [menu](https://wordpress.org/support/topic-tag/menu/)
 * [menu bar](https://wordpress.org/support/topic-tag/menu-bar/)
 * [primary menu](https://wordpress.org/support/topic-tag/primary-menu/)
 * [register](https://wordpress.org/support/topic-tag/register/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 2 participants
 * Last reply from: [Josh](https://wordpress.org/support/users/josh401/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/register-link-3/#post-5930657)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
