User Registration

Step by step documentation to set up a user registration form for your website.

How to add login/logout link in navigation menu programmatically

To add a login/logout link to the menu add the following code to your theme’s function.php. The codes will be wiped out with a theme update. So, you need to create a child theme and add it there. Here is the tutorial for that: https://themegrill.com/blog/tutorial-creating-wordpress-child-theme/ and add to your child theme’s function.php

add_filter( 'wp_nav_menu_items', 'ur_add_loginout_link', 10, 2 );

function ur_add_loginout_link( $items, $args ) {
     if (is_user_logged_in() && $args->theme_location == 'primary') {
           $items .= '<li><a href="'. ur_logout_url( get_permalink( ur_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>';
      } elseif ( ! is_user_logged_in() && $args->theme_location == 'primary' ) {
           $items .= '<li><a href="' . get_permalink( ur_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
      }
       return $items;
}
Note: Please visit this documentation to add the custom codes in your site.

Powered by BetterDocs

Scroll to top