Hi guys wondering if anyone can help. I have this code that lists all sub pages, their featured image and title/link. What I'd like to be able to do is randomize the the size of the featured image between what Wordpress offers... small/medium/large?

Any ideas?

    $args = array(
    'parent' => 2,
    'post_type' => 'page',
    'post_status' => 'publish'
$pages = get_pages($args);  ?>
foreach( $pages as $page ) {

    <a href="<?php echo  get_permalink($page->ID); ?>" rel="bookmark" title="<?php echo $page->post_title; ?>">
    <div><span class="thumbnail"><?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?></span>
    <span class="title"><?php echo $page->post_title; ?></span></div>

1 Answer 1


You can put the sizes into an array and use PHP's array_rand to choose a random size:

$sizes = array( 'small', 'medium', 'large' );

foreach( $pages as $page ){
    $random_size = array_rand( $sizes, 1 );
    echo get_the_post_thumbnail( $page->ID, $sizes[$random_size] );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.