Forums

[resolved] Redirect User To Different Page Based On Cookie (2 posts)

  1. Brandon
    Member
    Posted 7 months ago #

    Ok, I know this should be easy but having trouble getting it working. I've tried all sorts of hooks, combinations, etc.. and the best I've gotten is it showing up once for the user. Of course, trying a second time sends them to the wrong page. Anyway, here's the code:

    Basically, I'm trying to send a user to a different buy page if they are from Adwords. Pretty simple. The class I'm using is working and returning the proper data.

    Located in the mu_plugins directory:

    function adwords_redirect($query) {
    // page should they be redirected from
    if (is_page(832)) {
    
    	$aux = new GA_Parse($_COOKIE);
    
    	if($aux->campaign_source == "google" && $aux->campaign_medium == "cpc") {
                   //page they need to end up at
    		wp_redirect('http://domain.com/pricing');
    	}
    }
    }
    
    add_action('pre_get_posts', 'adwords_redirect');

    Any help is much appreciated. I'm stuck here and I know it's a simple thing I'm missing.

  2. Brandon
    Member
    Posted 7 months ago #

    I should be beaten for this one. Wow. Here's the solution. The answer was header instead of wp_redirect.

    function adwords_redirect($query) {
    if ($query->is_page(832)) {
    
    	$aux = new GA_Parse($_COOKIE);
    
    	if($aux->campaign_source == "google" && $aux->campaign_medium == "cpc") {
    
    		    header("Location: http://domain.com/pricing");
       			exit;
    	}
    }
    }
    
    add_action('pre_get_posts', 'adwords_redirect');

Reply

You must log in to post.

About this Topic