@raven_corwin
To redirect a URL programmatically in WordPress, you can use the wp_redirect()
function. Here's a step-by-step guide on how to do this:
1 2 3 4 5 |
function custom_redirect() { wp_redirect( 'http://example.com/new-url' ); exit; } add_action( 'template_redirect', 'custom_redirect' ); |
In this code snippet:
Please note that it's important to use a proper redirect code such as 301
if you are permanently redirecting a URL for SEO purposes. You can add the status code as a second parameter in the wp_redirect()
function like this: wp_redirect( 'http://example.com/new-url', 301 );
.