I'm trying to create some code that will accomplish the following:

  1. If login from any page in this array(example-page-one, example-page-two, example-page-three){ then, simply refresh the page

  2. } elseif login from 'example-page-four' { then, redirect to 'payment-page'

  3. } elseif login from all other pages { then redirect to '/member-account' }

So far, all I've accomplished is pulling out my hair. Any help would be greatly appreciated. I have very limited coding skills here. This is what I've cobbled together so far to test, but it doesn't work:

function custom_user_login_redirect($redirect_url) {

$page = str_replace('/', '', $_SERVER['REQUEST_URI']);

switch($page) {
    case 'example-page-one':
        return site_url('/example-page-one');

        return site_url('/member-account');

add_filter( 'login_redirect', 'custom_user_login_redirect' );

I know this code won't get me to all three requirements above, but I figured if I could at least get this to work, I might have a shot at getting the rest of it. Help!

  • var_dump the value of $page, $redirect_url, and $_SERVER['REQUEST_URI']` to see what you are comparing, then use die() to kill the request before the redirect happens. That will help debug a little. (edit and post the results if you can't figure it out). FYI, you'll need to return the value of $redirect_url at the bottom of that function to ensure the login redirect filter continues working elsewhere. – Jen Nov 15 '16 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.