Display Random Posts in WordPress – How to

Displaying random posts in WordPress is so easy read our full article and learn how you can attract visitors to your older posts.

Displaying random posts in WordPress give boost to your blog website and in the end result you get hundreds of post read up. Most of the time your post buried down and nobody dig deep to find out relative things. One of the user friendly way to give new life to your old post is to display random posts in sidebar. It will become an eye catching content and urge visitor to read it up. In this tutorial you will learn how to Display Random posts in WordPress.

Sidebar Widget:

Default WordPress theme have random posts capability and a widget ready with it. If random posts in WordPress not setup (usually content wrap in  <li> tag). Additionally code in your sidebar will give you the widget. All you have to do is open your sidebar.php, and paste the code.

Note: if you need to place your random posts widget then paste the following code in another file.

 <h2>Random Post</h2>
 $posts = get_posts('orderby=rand&numberposts=5');
 foreach($posts as $post) { ?>
 <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
 <?php } ?>


To customize this code or adding more post you need to change the Number 5 to your desired number e.g. 10. The best part you can compel use to read your post is Styling them in a creative way. By customizing your widget you can surely get visitors attracted to your website.

Having any problem or suggestion do write us in the comment box we will help you.

Leave a Reply

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