How to display random posts using the default Recent Posts Widget

You can use WordPress plugins such as Advanced Random Posts Widget to display posts randomly in the sidebar. But some users reported certain problems with this plugin. There is a way to display random posts in the sidebar without installing any plugins. You can leverage the default "Recent Posts Widget" for this purpose.

If you want to use the "Recent Posts Widget" as "Radom Posts Widget", please add the following function to your theme's function file (functions.php.)

add_filter('widget_posts_args','modify_widget');

function modify_widget() {
    $r = array( 'orderby' => 'rand' );
    return $r;
}

With this method, you can easily covert your recent posts widget to random posts widget without installing any plugins (and without slowing down your WordPress blog.)


Leave a Comment