0

In my unsubscribe script there is this command:

http://www.domain.nl/email-acties/[email protected]

after the unsubscribe I like to change the url into

http://www.domain.nl/email-acties/

But WordPress does not accept again header(). Also try

echo esc_url( remove_query_arg( 'email' ) );

That works but does not rewrite the url.

Question:

How can I rewrite the url as written above

2
  • Because you are trying to redirect too late. "Headers already sent" basically means the browser has started to receive the body of the HTTP response. Whatever hook you're using for your unsubscribe, you need to change it to one that runs early like init or template_redirect Commented Apr 15, 2016 at 14:10
  • I have moved the get_header(); lower in the code. Now it works fine.
    – Hermants
    Commented Apr 15, 2016 at 15:00

1 Answer 1

0

Why not create an if statement to check if the email arg was passed, if so, redirect to the URL without the email. Something like:

if ($_GET['email']) {
  //do unsubscribe stuff
  wp_redirect('http://www.domain.nl/email-acties/');
  exit;
}

Unsubscribed!

3
  • Hi, I get a failure. Warning: Cannot modify header information - headers already sent by (output started at /home/deb96951n2/domains/domain.nl/public_html/wp-includes/formatting.php:4587) in /home/deb96951n2/domains/domain.nl/public_html/wp-includes/pluggable.php on line 1171
    – Hermants
    Commented Apr 15, 2016 at 13:53
  • Because you're running your code too late - see my comment on your original question. Commented Apr 15, 2016 at 14:10
  • I have moved the get_header(); lower in the code. Now it works fine. Thanks both!
    – Hermants
    Commented Apr 15, 2016 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.