Post formats: `get_the_post_format_image()` splitting content doesn't work when "intermediate_image_sizes" result is empty
|Reported by:||lancewillett||Owned by:||markjaquith|
get_the_post_format_image() splits out an image from post content, to avoid duplicating it when a theme choose to output split content.
Unfortunately, not all WP installs will have "default" or "expected" image sizes, like 'thumbnail', 'medium', 'large' etc.
For example, on WordPress.com this call results in an empty array:
$sizes = get_intermediate_image_sizes();
I think to improve the content parsing two improvements can be made:
- Move get_attachment_link( $media->ID ) out of the foreach loop for $sizes -- that URL will be the same for each size, it's just the permalink to the attachment page
- Add the "original" image source path to the $urls array, which is the image path with no size information. The original uploaded file path can then be used to parse out images from the main content even if the expected size list is empty.