Use Safely Redirect URLs in WordPress

Prem Tiwari - - 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.


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.

Prem Tiwari

Prem Tiwari is the founder of and also a professional developer and a blogger by hobby.

Tags: , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.