Support » Plugins » Hacks » How to remove first image from the_content?

  • Resolved Alkorr


    Hi. I would like to remove the first image from the_content. It’s not an easy task but I’ve found a piece of code on this website but it looks heavy (the author says ‘It is not an elegant solution, but it works’) and it doesn’t work on my site (I get: Warning: preg_replace() [function.preg-replace]: Unknown modifier ‘I’ in /homez.32/mysite/www/bonto/wp-content/themes/v3/functions.php on line 60)…

    Does someone knows how to skip the first image and just show the_content without the first image?

    Thanks a lot for your help! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Did you try get_the_content? AFAIK it will simply take the raw text. Give it a try, and don’t forget to echo it out. 🙂

    Hi chaseman, thanks but using get_the_content function does the same as the_content. I’m using it on single.php.

    I searched again today and I can’t find a way to get ride of the first image in the_content.

    Still looking…



    Hi Alkorr,
    You can use the following code in place of the_content();

    echo preg_replace(“/\< *[img][^\>]*[.]*\>/i”,””,get_the_content(),1);

    Hi vinay! This code is amazing!! No need for to call a function, your code only is enough to do exactly what I want… Thank you so much for your help! 🙂


    Oh my. I have been looking for something like this for a long time. So many themes have no sensible way to limit images in archives. I get both a thumbnail and the full-size image. Until now. Thanks for this code.


    Very helpful! I had a mix of images and images with captions so I modified the code to remove the caption info as well:

    echo preg_replace("/\[caption .+?\[\/caption\]|\< *[img][^\>]*[.]*\>/i","",get_the_content(),1);

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to remove first image from the_content?’ is closed to new replies.