Notfornoone
Yes, its a double negative.





Simplify Your WordPress Redirects with This Handy Function

Greetings, WordPress enthusiasts! Today, we're thrilled to share a nifty piece of code that will make your life easier when handling redirects in your WordPress functions.php file. We've crafted a convenient wrapper around the wp_redirect function, designed to streamline your redirection needs.

Introducing wptf_redirect: Your Go-To Redirect Solution

Here's a quick look at our user-friendly function:

```php
/
  A handy wrapper to wp_redirect, ensuring a clean exit.
  $location can be a URL or a post ID.

  @param string|integer $location
  @param int $status HTTP status code (defaults to 302)
  @return bool False if $location is not set
/
function wptf_redirect($location = '', $status = 302) {
$permalink = false;

if (is_int($location)) {
$permalink = true;
$location = get_permalink($location);
}

if (!$location) {
return false;
}

if (!$permalink) {
$location = ltrim($location, '/');
$location = '/' . trailingslashit($location);
$location = get_bloginfo('url') . $location;
}

wp_redirect($location, $status);
exit;
}
```

Why Use wptf_redirect?

1. Simplicity: Our function simplifies the process of creating redirects in WordPress. Whether you're redirecting to a URL or a post ID, wptf_redirect has you covered.

2. Clean Exits: We've ensured that PHP exits gracefully after executing the wp_redirect function, preventing any unexpected issues that may arise from incomplete redirects.

3. URL Perfection: When dealing with URLs, we've accounted for leading slashes and appended them as needed, ensuring your redirects function flawlessly.

How to Use wptf_redirect

Using wptf_redirect is a breeze. Insert the function into your theme's functions.php file, and you're all set to create efficient and clean redirects throughout your WordPress site.

```php
// Example Usage
wptf_redirect('https://your-website.com/new-page');
```

Conclusion

Simplify your WordPress development by adding the wptf_redirect function to your arsenal. This handy tool will help you manage redirects effortlessly, ensuring your website's user experience remains seamless.

Feel free to explore the possibilities and tailor this function to your specific needs. Happy redirecting!