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!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at Unwanted.cloud

RSS Latest posts from my personal blog


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

Full-stack impostor syndrome sufferer & Software Engineer at Schibsted Media Group

Comments 4