Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ravinsharma12345/7887239 to your computer and use it in GitHub Desktop.
Save ravinsharma12345/7887239 to your computer and use it in GitHub Desktop.
<?php
/**
* @package Redirect to homepage after logout
* @version 0.1
*/
/*
Plugin Name: Redirect to homepage after logout
Plugin URI: http://daankortenbach.nl/wordpress/redirect-to-homepage-after-logout/
Description: Redirects the user to the homepage after logout
Author: Daan Kortenbach
Version: 0.1
Author URI: http://krtnb.ch/
*/
add_filter('logout_url', 'dmk_logout_redirect_url', 10, 2);
/**
* Adds a redirect url to the homepage to $logouturl
*
* @author Daan Kortenbach
* @param string $logouturl Existing logouturl
* @return string $logouturl Amended with redirect url
*/
function dmk_logout_redirect_url( $logouturl ) {
return $logouturl . '&amp;redirect_to=' . urlencode( get_option( 'siteurl' ) );
}
add_action( 'init', 'dmk_loggedout_redirect' );
/**
* Redirects if loggedout is true in case a custom logouturl is used.
*
* @author Daan Kortenbach
*/
function dmk_loggedout_redirect() {
if( $_GET['loggedout'] == 'true' ) {
wp_redirect( get_option( 'siteurl' ) );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment