In your Child theme in functions.php add these lines of code:
/* Shortcode for random posts */
/* The shortcode to put in any post/widget is [my-random-posts] */
function my_rand_posts() {
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 3,
);
$the_query = new WP_Query($args);
$string = "";
if ($the_query->have_posts()) {
$string .= '<ul>';
while ($the_query->have_posts()) {
$the_query->the_post();
$string .= '<li><a href="' . get_permalink() . '" target="_blank">' . get_the_title() . '</a></li>';
}
$string .= '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
}
return $string;
}
add_shortcode('my-random-posts', 'my_rand_posts');
add_filter('widget_text', 'do_shortcode');
This code will create shortcode which you can put whenever you like! On line #8 (posts_per_page) you can choose how many posts will be shown - in our case: 3.
The shortcode to put in any post/widget is: [my-random-posts]
Enjoy!