X

Remove all images from the_content in a post

Adding this snippet to your wordpress template index.php replacing the default the_content(); will remove images from the post. This is a great snippet if you want to display a number of images on single.php but not on the main blog view. Keep in mind that this will not remove the captions so don't insert the images with a caption or disable all captions.



Code Snippet:


<?php
echo preg_replace('/<img[^>]+./','',get_the_content());
?>

Comments  Leave a Reply

  1. what if i want the image to show up but be linked to the post instead of the image itself?

  2. thats what i was searching for! thank you.

  3. Nice!!! thanks

  4. very useful. thanks

    1. No problem glad that I could help!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!