I’d like to know how to do this using header.php (WordPress) or any other method. Basically, I want to set up a redirect from a subdirectory page (e.g. "/my-ebook/") to an external website (e.g. Gumroad).
So, when people visit "/my-ebook/", they’re redirected to my Gumroad profile page, for example. I know a plugin can do this, but want to know a way to do this without using a plugin. Thank you in advance.
2
Answers
The
template_redirect
action is probably the most appropriate action to use, but you could probably use an mu-plugin to run as early as possible.Here’s with the
template_redirect
action (add to your theme’sfunctions.php
):For an mu-plugin, take out the code within the action’s callback and place it in
wp-content/mu-plugins/gumroad-redirect.php
:You can use multiple method for it but here is suggested 2 methods
first for
functions.php
And second method is
.htaccess