wordpress logout link

To add a WordPress logout link, follow these steps:

  1. Navigate to your WordPress theme directory.
  2. Locate the functions.php file within the theme directory.
  3. Open the functions.php file using a text editor.
  4. Add the following code snippet to the file:
function add_logout_link($items, $args) {
    if ($args->theme_location == 'primary') {
        $items .= '<li class="menu-item menu-item-type-custom menu-item-object-custom"><a href="' . wp_logout_url() . '">Logout</a></li>';
    }
    return $items;
}
add_filter('wp_nav_menu_items', 'add_logout_link', 10, 2);
  1. Save the changes to the functions.php file.
  2. Visit your WordPress site and refresh the page.

Now, a "Logout" link should appear in the primary navigation menu. Clicking on this link will log the user out of the WordPress site.