Get all Post Images in WordPress

Single post pages with multiple images like a photoset, etc. can be very resource heavy when browsers download images that are larger than needed. The method below allows you to designate the initial size (thumbnail, medium, large or full), while using the native WordPress responsive image support by including srcset and sizes attributes to the image. Browsers will download the most appropriate size and ignore the others. This method also ignores the Featured Image of a post.

<?php
function evo_all_post_images() {
	global $post;
	$args = array(
		'post_type'   => 'attachment',
		'numberposts' => -1,
		'post_status' => 'any',
		'post_parent' => $post->ID,
		'exclude'     => get_post_thumbnail_id(),
	);
	$attachments = get_posts( $args );
	if ( $attachments ) {
		foreach ( $attachments as $attachment ) {
			echo wp_get_attachment_image( $attachment->ID, 'large', false, array( 'class'=>'img-responsive-post' ) );
		}
	}
}

Use the function in the loop like this.

<?php evo_all_post_images(); ?>