Redirect after login to current URL

I've my login box on any page of my WordPress and I'm trying to redirect to the same page after a user logs in.

For example: If I make the login in the URL http://localhost/wordpress/category/sub-category/sold, redirect to the same URL.

I've this in my functions.php but, using my $url doesn't work.

How can make the redirection?

function login_go_home(){
    //$url ="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    wp_redirect(home_url());
    exit();
}

Topic wp-login-form functions login Wordpress

Category Web


I need to do the next step:

To redirect my logout, I put the next code in functions.php

function out_home(){        
    wp_redirect(home_url());
    exit();
}
add_action("wp_logout","out_home");

In my header.php, to change the value of my URL in the login:

$URL_POSTLOGIN = add_query_arg(array(),$wp->request);
    function login_go_home($URL_POSTLOGIN){         
        wp_redirect($URL_POSTLOGIN);
        exit();
    }
    add_action("wp_login","login_go_home");

Maybe is not the best solution but in my case others codes fails.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.