wordpress logout link
To add a WordPress logout link, follow these steps:
- Navigate to your WordPress theme directory.
- Locate the
functions.php
file within the theme directory. - Open the
functions.php
file using a text editor. - 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);
- Save the changes to the
functions.php
file. - 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.