I am trying to create an unsubscribe page for my members, but in order to see the unsubscribe form, they have to be logged out, so the first link is:
/wp-login.php?action=logout&_wpnonce=ba51bbcdc3.
Once they are logged out, I need them redirected to the unsubscribe form, but I can’t just set up a forward, because this is also the login page.
You can use the
wp_logout_url()
template tag to generate a logout link. You can specify the URL that the user will be redirected to as the first pramiter:The above code will generate a URL that looks a bit like this:
/wp-login.php?action=logout&_wpnonce=ba51bbcdc3&redirect_to=http://example.com/unsubscribe
. You can make it into a link like so:If you want to use this in a page or post, you need to create a shortcode:
You can then add
[unsubscribe-link]
to a post or page where you want the link to appear.If you’re redirecting to another website besides your own, you need to add this code to your
functions.php
file (replaceexample.com
with the domain of the site):Use this code if you are using it at menu at menu manger
WordPress includes a template tag which you can use:
wp_logout_url()
. It’s a few simple lines of code if you want to redirect users to another URL after they sign out.I wrote a tutorial late last year on how to use this template tag. In summary, you need to create a filter in
functions.php
and then create a Logout link insidebar.php
.If you’re redirecting to another website besides your own, you need to add this code to your
functions.php
file (replaceexample.com
with the domain of the site):You then need to add this line to your
sidebar.php
file or anywhere you can execute PHP: