How to Remove Images From Post Content in WordPress (Classic and Block Editor)
On a blog listing you may want text only. Here is how to strip images from post content for classic and block editor posts, and when an excerpt is the simpler answer.
To show WordPress post content without images, filter the images out before printing. For block editor content, remove core/image and core/gallery blocks with the render_block filter on the pages where you don’t want them. For classic content, strip <img> tags with preg_replace() on the filtered content. If you only need a text preview on the home or archive page, a trimmed excerpt with wp_trim_words() is simpler and faster.
Originally published in May 2011 for classic editor posts. Rewritten in December 2026 to cover the block editor.
Option 1: Use an excerpt
For listings, this is usually what you want:
echo wp_trim_words(get_the_excerpt(), 40, '…');get_the_excerpt() uses the manual excerpt if the post has one, and otherwise builds one from the content with tags removed, so images are already gone.
Option 2: Remove image blocks (block editor)
Block editor images are wrapped in <figure> elements with captions. Removing just the <img> tag leaves empty figures and orphaned captions. Remove the whole block instead:
add_filter('render_block', function ($html, $block) {
if (is_admin() || !(is_home() || is_archive())) {
return $html;
}
if (in_array($block['blockName'], ['core/image', 'core/gallery', 'core/cover'], true)) {
return '';
}
return $html;
}, 10, 2);This runs only on the blog home and archive pages, and leaves single posts untouched. Add other block names, such as core/media-text, if you use them.
Option 3: Strip img tags (classic editor)
Classic posts store images as plain HTML, sometimes wrapped in links or shortcodes:
$content = apply_filters('the_content', get_the_content());
$content = preg_replace('/<figure[^>]*>.*?</figure>/is', '', $content); // captions
$content = preg_replace('/<a[^>]*>s*<img[^>]*>s*</a>/i', '', $content); // linked images
$content = preg_replace('/<img[^>]*>/i', '', $content);
echo $content;Applying the_content filters first turns shortcodes into <figure> markup, so the first pattern can remove them with their captions.
Regular expressions aren’t a full HTML parser, but for removing images from your own post content they work reliably.
Show the featured image separately
A common reason to strip images is to show one consistent image per post. Use the featured image for that:
if (has_post_thumbnail()) {
the_post_thumbnail('medium_large', ['loading' => 'lazy']);
}Common questions
Will this remove images from the post itself?
No. These methods change only what’s printed. The saved post content stays the same.
How do I remove only the first image?
For classic content, pass a limit of 1: preg_replace('/<img[^>]*>/i', '', $content, 1). For blocks, track whether you’ve already removed one inside the filter with a static variable.
Does removing images help page speed?
On listing pages, yes. Fewer images mean fewer downloads. On single posts, use lazy loading and correctly sized images instead of removing them.