How to Display Random Posts in WordPress
Are you looking for an easy way to add random posts on your WordPress website? Well keep reading in this article I’ll walk you through two methods you can use to add random posts in WordPress. To get started let’s head over to your WordPress dashboard.
We want to go over to our plugins area we’ll click Add new.
And we’re searching for a plug-in called Advanced random posts widget this is the one we want, so let’s go ahead and install it.
Now once you install it you need to go ahead and activate it as well.
Now that it’s activated you see it here we can go over to Appearance -> Widgets and we’ll add this to our sidebar area.
Random Posts is the widget we want so we’ll just left-click
and drag this up and I’ll put it right there.
To see what it will do let’s go over to the posts tab
and you’ll see that we can ignore the sticky posts, you can set the number of posts here, and for this demonstration out-of-the-box plugin default settings will work just fine.
Us let’s go ahead and click Save.
And now we can head over to the site to see it in action and you see when I scroll down these are the random posts that show up and you can see how it changes when I click Refresh.
There are different posts that are showing up so each person who visits your site will get random posts when they visit. The second method is a little bit more advanced and it’s to show posts in WordPress using code. So if you’re comfortable with that then you can do it this way. What you want to do is grab this function that we’ve created on our site.
And you can copy this and you would want to paste this in your functions.php file,
and then you can add the shortcode of wp-random posts in the area where you want the random posts to go. So we’ll go into the editor area, we’ll open up our functions page.
I want to scroll all the way down to the bottom and I’ll add that code here.
Then we can update the file.
We’ll go to our widgets area, I’m going to remove this so you don’t see that.
now to add the shortcode we’ll add the we’ll left click and drag the text widget up to the top
and we’ll add the shortcode here.
We’ll click Save
and now when you go to the site you’ll see the posts that are on there.
That are randomly selected based on the code that we put in our functions.php file.