I have a page template that outputs all posts with minimal formatting - no headers, footers, sidebars, etc.
With the loop, the_content()
is used to output content (text and images).
I need to output all images in 'full' or 'large' size. Currently, the_content()
in the loop is returning an img tag similar to this - always thumbnail.
<img
src="https://www.example.com/wp-content/uploads/sites/21/2016/10/sample-picture-150x150.jpg"
class="attachment-thumbnail size-thumbnail" alt=""
size="full" width="150" height="150">
This causes the resolution of the image to be less than what I need.
I tried using the wp_get_attachment_image_attributes
filter to force the size attribute to 'full', but that didn't work:
function my_fix_attachment_size($attr, $attachment, $size) {
// Full width header images
$attr['size'] = 'full';
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'my_fix_attachment_size', 10 , 3);
How to I get the_content()
to output full size images? In the post, there could be images or galleries, so need to handle both.
Note that I do not need to set/change image sizes, but just force full size in the generated page.I am also not worried about the viewport size, as the generated page is used to create a document.
Added
After much googles and expirementation, I came up with a solution that worked for me (below as an answer). I suspect there are better ways to do this, but this is the only one that worked for me.
Additional answers are welcomed.
wp_get_attachment_
filters or functions are run. You would need to parse the HTML, find image tags, extract the image ID, get the full size of the image, then replace the image tag.