When inserting a image to WordPress post, I have used size as "Full Size" for all images. My images width are between 800px to 1500px.

Is there way to change it for whole site when displaying on the post page?

I mean I want do display thumbnail size (let assume 700px width thumbnail size) for all posts in single post page....

So I can speed up the my site.

Is it possible?

1 Answer 1


You can use regex if you want to display it on all existing posts. WordPress add a wp-image-ATTACHMENT_ID class on images. We can use it to find the attachment_id then grab the new url. For example here, with medium size.

wp_get_attachment_image_src : https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

We apply this filter to the content to update the display of your posts. We use regex to find attachment_id and image src attribute.

function wpse_289055_new_image_size($content) {
    preg_match('/wp-image-[0-9]*/', $content, $matches);
    if($matches !== NULL)
        $thumb = wp_get_attachment_image_src(intval(str_replace('wp-image-', '', $matches[0])), 'medium');
            preg_match('/ src="([^"]*)"/', $content, $matches);

                $content = str_replace($matches[1], $thumb[0], $content);
    return $content;
add_filter('the_content', 'wpse_289055_new_image_size');

In my opinion if you don't use a cache system, this code use some ressources. Adapt this one to update all your existing post directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.