Display Random Posts in WordPress: A Guide

Adding random related posts to your website is a great way to keep your readers engaged and on your site for longer periods of time. It also helps spread out links across your site, which can be beneficial for SEO purposes. In this article, we will discuss two ways to display random related posts on your WordPress website.

Display Random Posts With Code

The first method to display random related posts is with code. This method is relatively easy and can be achieved with a simple call to the database. Plus, there are a few WordPress template tags that you can use for various effects.

To show a list of random posts, you can insert the following code wherever you want them displayed and then tweak accordingly:

“`

// Query random posts

$the_query = new WP_Query( array(

‘post_type’ => ‘post’,

‘orderby’ => ‘rand’,

‘posts_per_page’ => 3,

) ); ?>

// If we have posts lets show them

if ( $the_query->have_posts() ) : ?>

Stay in Touch

spot_img

Related Articles