How to add a random image to a post from gallery and only show one?
You should use the ‘orderby’ => ‘rand’ parameter for the get_children() attachments function. For instance: $images = get_children( array( ‘orderby’ => ‘rand’, // this is random param ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => get_the_ID(), );