How to add custom logout function and custom redirect after logout in wordpress
Just Copy and paste below code into your theme's functions.php or your custom plugins file
functions.php
<!--?php add_filter( 'logout_url', 'rj_custom_logout_url', 10, 2 );add_action( 'init', 'rj_custom_logout_action' );function rj_custom_logout_url($logout_url, $redirect){ $url = add_query_arg( 'action', 'wlt_logout', home_url( '/' ) );$url = wp_nonce_url($url,'wlt_logout','_nonce'); if ( ! empty ( $redirect ) ) $url = add_query_arg( 'redirect', $redirect, $url ); return $url;} function rj_custom_logout_action(){ global $wpdb; if(isset($_REQUEST['_nonce']) && wp_verify_nonce($_REQUEST['_nonce'],'wlt_logout')) { wp_logout(); $loc = isset ( $_REQUEST['redirect'] ) ? $_REQUEST['redirect'] : home_url( '/' ); wp_redirect($loc); exit(); }}?-->
