How to remove first image from the_content

We can use the following code in place of the_content() to remove first image

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

or we can use hook to remove from the_content as following:
put the following add_filter before the_content in any file you want to remove image

 add_filter('the_content', 'remove_image_content');
the_content();

or you can put filter on functions.php to remove first image from all the_content

  add_filter('the_content', 'remove_image_content');

And put the following function on functions.php

 function remove_image_content($content) {
return preg_replace("/\< *[img][^\>]*[.]*\>/i","",$content,1);
}

Comments

comments

Leave a Reply