I don’t think there exists such function in the WordPress core.
Example #1
But you can try something like this:
/**
* Random image size
* @return String Image size
*/
function wpse_random_image_size()
{
$sizes = (array) get_intermediate_image_sizes();
return $sizes[array_rand( $sizes )];
}
to display a random image size.
Usage:
if ( function_exists( 'wpse_random_image_size' ) )
echo wpse_random_image_size();
Example #2
If you want to exclude certain image sizes, e.g. thumbnail
and medium
then you can use:
/**
* Random image size
* @param Array | String Sizes to exclude
* @return String Image size
*/
function wpse_random_image_size( $exclude="" )
{
$sizes = array_diff( (array) get_intermediate_image_sizes(), (array) $exclude );
return $sizes[array_rand( $sizes )];
}
Usage:
if ( function_exists( 'wpse_random_image_size' ) )
echo wpse_random_image_size( $exclude = ['thumbnail', 'medium' ] );