Wordpress SEO - What are you looking for?

If you're looking for answers to SEO or wordpress related questions, type in a phrase and wait for hints or click enter! The results also show links to external sources.

161 articles in the database

How to display random posts in WordPress?

[ Article content is protected by Plagiashield ]


If you are running blog for several years and you've been actively adding entries on it, I'm sure several hundred articles have accumulated over that time. Some of them are more popular among users and is visited regularly. Another is visited less frequently and doesn't generate as much interest in readers. And more often it happens that an entry which yet a week ago it caused active discussions, today it is forgotten via users.

Every blogger has surely encountered a similar situation. There is nothing strange in it. It is known that the information is interesting as long as there is a query on it in users. Especially in the IT field, where Technologies change rapidly and new solutions replace their predecessors. That's why bloggers use various tricks to make sure visitors don't forget about older entries: add widgets with popular articles, recommended topics, entries that have the most comments, etc. We are sure that you also use such solutions on your own blog. From its websites Today we are going to show you another way to keep your older articles read and commented by the users of the site. It is all about article draws.

Added entries in WordPress are displayed in reverse chronological order. This way visitors will be the first to know about new articles. Because of this, posts that were published earlier may not make it to the eyes of site visitors. Therefore can be add to side panel additional widgetwhich will display random articles. Then new and old entries will be mixed, co will allow users to explore the various topics of your site.

We will present you 2 ways to implement the above idea. One of them - using a plugin, and the other - by adding code to the file functions.php.

Method 1 - Installing the Advanced Random Posts Widget plugin

This is not the only plugwhich will allow you to draw blog posts. When you add the query "Random Posts" under search plugs on the repository WordPress As many as over 1200 elements can be found (Fig. 1).

Search result on the repository WordPress

Therefore, you can choose any other solution. In our case, we chose the Advanced Random Posts Widget plugin because it is easy to use and contains the options we're interested in.

After installing and enabling this plugin, the corresponding "Random Posts" widget will appear. You can find it in the section Appearance - Widgets panel administration (Figure 2).

Figure 2: Random Posts widget

Next, using the Drag and Drop method, we will move this widget to the side panel (Figure 3).

Figure 3 Options widget Random Posts

The Advanced Random Posts widget is a powerful plugin with a huge number of settings. You can select different record types, display quotes or thumbnails, skip unnecessary records or display posts about relevant categories and tags.

In our case, we will select 5 entries to display and in the category "Thumbnail" set the option display thumbnail. After saving the changes, we move on to the blog (Fig. 4).

Figure 4: Widget with drawn entries

Like you can see from this picture some of the entries have no thumbnails and others are cloned. I'm using the free GPL Monstroid 2 Lite theme, which due to license restrictions contains only cloned images. If you do not rub on the quality of the graphics, you can say for sure that the plugin works and the widget displays the drawn entries.

Method 2 - modification of functions.php file

The provided method will allow you to manually make changes to the theme function file used by default. Before implementation of all the changes we recommend to create themes descendant and edit the file functions.php the specified theme. This allows you to protect your changes from being lost in future updates. templates.

Make changes to the file functions.php can be done in several ways. We will use the built-in WordPress editor for this purpose. Therefore, we will go to the section Appearance - Editor and choose from the available theme files functions.php. At the end of this file, we insert the following code (Figure 5):

function devise_rand_posts() {

$args = array(
	'post_type' => 'post',
	'orderby' => 'rand',
	'posts_per_page' => 5,

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {

$string .= '
    '; while ( $the_query->have_posts() ) { $the_query->the_post(); $string .= '
  • '. get_the_title() .'
  • ' } $string .= '
'; /* Renewing the original Post Data */. wp_reset_postdata(); } else { $string .= 'posts were not found' } return $string; } add_shortcode('devise-random-posts','devise_rand_posts'); add_filter('widget_text','do_shortcode');

In the variable posts_per_page you can set an interesting number of entries to be displayed

After saving all changes, we can use shortcode Devise_rand_posts] to display random entries. Therefore, we will go to the section Appearance - Widgets and add a text widget to the side panel. Into it we will insert the appropriate shortcode (Figure 5).

Figure 5: Modification of functions.php file

Save the changes and go to blog. The following result will be obtained (Figure 6):

Figure 6: Widget with random entries

As you can see from Figure 7, our shortcode has drawn 5 blog posts. So, the code is working correctly.


Running a blog is not such a simple matter as it may look at first glance. A blogger must not only write good posts, but also always combine with the design of the site to attract the attention of visitors to the published articles. Today's solution will show random blog posts to the readers. This will make your older posts more likely to be read and commented by users. This will be an additional incentive for you to prepare new contents.


O Janusz Kaminski

Company marketing specialist TemplateMonster. He has been working in the IT industry for 5 years. He has experience in SEO, internet marketing. Apart from that he is interested in web designing.
  • Internal Links and Sematics

  • Link building
  • Sematics
  • Link building has never been easier. Hundreds of link possibilities in one click.
  • See

[ Article content is protected by Plagiashield ]

SEMRush - the best tool for SEO and PPC.

Read previous post:
Copywriting and text formatting in accordance with SEO rules. Guide for beginners

Everyone was once just an aspirant in their master field dreaming of greatness. If you have come across this article then clearly your...