Add logOut page to menu

Hi,

I want to add a LogOut button to my primary menu as Im using a forum plugin.

I have added a custom link to the menu called it ‘LogOut’ and ideally when its clicked it logs the user out without going to the default logout page, and then re-directs the user to a certain page.

Ive tried a few href links but they all seem to take me to the default log out. Ideally you just click it, it logs you out and you land on a set re-direct page

I have worked out how to add ‘LogOut’ to the main nav if the person is logged in.

All good, but being picky I was wondering if rather it going to the log in page, if the user can be redirected to another page after being logged out.

<?php
function add_login_logout_register_menu( $items, $args ) {
 if ( $args->theme_location != 'primary' ) {
 return $items;
 }
 
 if ( is_user_logged_in() ) {
 $items .= '<li><a href="' . wp_logout_url() . '">' . __( 'Log Out' ) . '</a></li>';
 } else {

 } 
 return $items;
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );
?>

Problem solved, posted below if anyone needs to use it.

<?php
function add_login_logout_register_menu( $items, $args ) {
 if ( $args->theme_location != 'primary' ) {
 return $items;
 } 
 if ( is_user_logged_in() ) {
 $items .= '<li><a href="' . wp_logout_url('/support-forum/') . '">' . __( 'Log Out' ) . '</a></li>';
 } else {

 } 
 return $items;
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );
?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.