WordPress How-To: Create a Redirect to a Random Post

Prior to WordPress version 3.8, I had this wonderful little plugin called “Random Redirect” written by Matt Mullenweg. That little plugin served this blog, and Bionic Beauty, for over four and a half years! Sadly, WordPress 3.8 with Jetpack completely borked the use of Random Redirect and its successor, “Random Redirect 2”.

Creating magic with WordPress - tutorials by Bionic StyleWhat’s a blogger to do? I LOVE my little “Surprise Me” graphic in the sidebar that whisks readers off to a random post. It’s simply awesome.

I set off seeking a replacement.
And ker-splat.
Nothing worked.

Then… a lightbulb moment! I already have the completely awesome “Redirection” plugin by John Godley. I’ve used it in the past to handle 301 redirects with ease.

In this case, we’re looking for a nifty bit of code to allow website visitors to click on a link (or image), such as the Surprise Me graphic in this site’s sidebar; the click action needs to trigger the code to magically send the visitor to a random article.

How to Make the Magic:

  1. Install the Redirection plugin by John Godley. Get it at Godley’s own website or from WordPress.org.
  2. Active the plugin.
  3. In your WordPress admin, select Tools, then Redirection.
  4. In “Add New Redirection” type: http://your-domain.com/?random  *Remember to replace your-domain.com with your own domain name.
  5. Set Match field to “URL only”.
  6. Set Action field to “Redirect to random post”.
  7. Tap that Add Redirection button to save!
  8. Head over to your theme/layout/code/wherever you’d like your redirect placed and insert the link using the code from step 4:  http://your-domain.com/?random
  9. For example: < a href="http://bionic-style.com/?random" title="Read a random article on Bionic Style!">Random Post!< /a>. *If you copy/paste this code directly, be sure you remove the spaces after each “<“.
  10. Enjoy the wondrousness that is a surprise random redirect to one of your own articles!

Happy coding,
Jami - author and editor of the Bionic Style blog

2 thoughts on “WordPress How-To: Create a Redirect to a Random Post

  1. Reply Sharmanyasa Jun 11,2014 12:45 AM

    I have read this post, it’s really very interesting.

Post a Note


Get every new post delivered to your Inbox

Join other followers: