Blogging, Webmaster, Wordpress

WordPress: Redirect Blog to First Post

14 Comments

I just created a simple WordPress installation. It was only going to be short pages and a simple shopping cart, but at the last minute, they decided to add a blog. Since the area for text was so small, we decided to only have one post for every page. As it would only act as duplicate content, there is no point in using the blog home page at all.

With some help from WP Recipes, I created this code to redirect the blog home page (home.php template in the WordPress Theme Folder) to the first post:

<?php
/*
home.php (Blog Home Page):
Redirect To First Post
*/
if (have_posts()) {
  while (have_posts()) {
    the_post();
    wp_redirect(get_permalink());
  }
}
?>

It’s actually very simple. It just uses the WordPress Redirect function to redirect to the first permalink that would show up on that page.

Enjoy,
Ashton Sanders

14 Comments

Leave a Reply to mark Cancel reply

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