Useful Snippets

Welcome!


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

RSS Latest posts from my personal blog


Most viewed posts


Subscribe to RSS feed


Redirect to base URL on logout in WordPress

Stanislav KhromovStanislav Khromov

After a user signs out, the default behaviour in WordPress is to send the user back to /wp-login.php

However, it’s usually more desired to send the user back to the base / root URL for their site. Here’s a small plugin that accomplishes exactly that:

<?php
/*
Plugin Name: Redirect to Base URL on logout
Plugin URI: https://snippets.khromov.se/redirect-to-base-url-on-logout-in-wordpress
Description: Redirect to Base URL on logout
Version: 2015.01.11
Author: khromov
Author URI: https://snippets.khromov.se
License: GPL2
*/
add_action('wp_logout', function()
{
    wp_redirect(get_home_url());
    exit;
});

If you prefer, you can use the code block (without plugin header) directly in your themes functions.php file.

PHP

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
LinkedIn
Twitter
WordPress.org Profile
Visit my other blog

Comments 4