Introduction

The WordPress plugin Redirect URL to Post sends your visitors to your first, your last, the previous, the next, a random, or any other post in single-post view.

It works invisibly in the background. All URLs (links) that contain ?redirect_to=… redirect to a post that is determined by this and other parameters. The result depends on the available posts at the time when the redirect happens. The latest post, for example, can be different today and tomorrow.

Here is an example: Imagine your website address is https://www.example.com. We add a piece to the end to redirect to the latest post:

https://www.example.com?redirect_to=latest

And that’s it! Whenever someone visits this address, the browser will immediately continue to the post that is the latest at that moment. You won’t see a list of posts or any dialog. Just a post as final destination.

You can use the resulting URL as a link, in a menu or button, or you can even send it around in a newsletter or post it on social media. When your visitors access this URL, they will immediately be redirected to the post.

All other URLs that don’t contain ?redirect_to are naturally not affected.

How to compose the URL

There are three types of parameters. Only the first one is mandatory.

1. Determine the target: random, first, last, previous, next, …

The only mandatory parameter is the target parameter redirect_to.

Some technical background information: This parameter basically determines a sort order of all relevant posts. We then redirect to the post that ends up on top of that ordered list.

2. Determine the post base

Then you can add filter parameters in order to narrow down the list of posts to a specific subsample. You could, for example, pick a random post from author John Doe (filter by author) or the latest post that is at least one month old (filter by time).

Note: The default post base are default WordPress posts. If you want to use this plugin with any other post type (products, gallery items, testimonials, …), you need to use the post_type parameter. Example for WooCommerce.

3. Tracking, caching, default target, …

Lastly, we have other optional parameters that determine what will happen if no post was found, that set the caching time, that enable tracking with Google Analytics or Matomo, or that determine if you want visitors to pick each random post only once and then start over again or something else.

Now add them all to your WordPress site’s URL

The URL is composed according to the following pattern:

[your WordPress site's URL]?redirect_to=[target]&[further_parameter]&[further_parameter]...

The order of the parameters doesn’t matter, but you have to make sure that you first use “?” and afterwards always “&” when you glue the pieces together.

If you anywhere need to use spaces, you write them as %20.

So you could end up with an URL like this:

https://www.example.com/?redirect_to=random&before=yesterday&after=last%20month&cache=600

Tip: Save the URL to your clipboard1 before you hit Enter because it will disappear and be replaced by the target post’s URL. If you need to debug a redirect you can add a parameter that shows you what would have happened, without actually doing the redirect.

Examples

You can get some inspiration about what is possible on the page with redirect examples.

Next

Click on the “Next” navigation below.

Footnotes

  1. ctrl/cmd-a, ctrl/cmd-c[]

How do you rate this article?