Use Safely Redirect URLs in WordPress

| Last Updated: | In: WordPress Snippets


In this tutorial, I will explain how to use safely redirect URLs in WordPress. The wp_safe_redirect() function does not exit automatically, if you are using this function in your code, then you should always used the exit(). See the below example:

Use Safely Redirect URLs in WordPress

You can use the below code in your theme’s files & template files to redirect to any custom URLS.

Description:

1) $location is a string and required parameter, it would be the URLS where page redirects.

2) $status is an integer and optional parameter, it would be the status code like 301 or 302. If you have not used this parameter, then the default value is 302.

wp_safe_redirect Example

Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:

Tags: , , , , , , , ,