Leave a Reply

1 comment

  1. Replacing just the URL is not enough. You have to tell WordPress what to do with the new URL.

    Sample code, creates a log-out URL like example.com/logout=1 and redirects to front page or custom URL after logging the user out:

    add_filter( 'logout_url', 't5_custom_logout_url', 10, 2 );
    add_action( 'wp_loaded', 't5_custom_logout_action' );
    
    /**
     * Replace default log-out URL.
     *
     * @wp-hook logout_url
     * @param   string $logout_url
     * @param   string $redirect
     * @return  string
     */
    function t5_custom_logout_url( $logout_url, $redirect )
    {
        $url = add_query_arg( 'logout', 1, home_url( '/' ) );
    
        if ( ! empty ( $redirect ) )
            $url = add_query_arg( 'redirect', $redirect, $url );
    
        return $url;
    }
    
    /**
     * Log the user out.
     *
     * @wp-hook wp_loaded
     * @return  void
     */
    function t5_custom_logout_action()
    {
        if ( ! isset ( $_GET['logout'] ) )
            return;
    
        wp_logout();
    
        $loc = isset ( $_GET['redirect'] ) ? $_GET['redirect'] : home_url( '/' );
        wp_redirect( $loc );
        exit;
    }
    

    As plugin on GitHub, because this is pure plugin territory. And you cannot really hide WordPress.


    it also appends title= to the end of the URL

    I guess the problem is markup like this:

    <a href="<?php echo wp_logout_url(); ?> title="Log out">Log out</a>
    

    Note the missing ".