Home / posts / Remove all images from the_content in a post
  • How to Remove all images from the_content in a post

    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.

    ( click code to copy )

    wordpress snippet : PHP

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

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, get_the_content,
  • nasibasoft

    very useful. thanks

  • Nice!!! thanks

  • Hans

    thats what i was searching for! thank you.

  • box

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