Redirect home page to a random blog post

This is a slight mod of the wordpress post from yesterday (Redirect home page to first blog post) and think you might enjoy it. Add this snippet to the index.php template of your wordpress theme before get_header(). Your home page will automatically redirect to a random post from your wordpress database.

 

 

<?php
if (have_posts() && is_home()) {
query_posts('orderby=rand');
while (have_posts()) {
the_post();
wp_redirect(get_permalink());
}
}
?>

Be Sociable, Share!

Leave a comment