HomeHow To

Ways to remove images from WordPress post content

Ways to remove images from WordPress post content
Like Tweet Pin it Share Share Email

When you have a featured image , you don’t need the same image that you have in your WordPress post or article. So to avoid duplicate image on your theme , either you can disable the thumbnail or remove the images from your wordpress post.

How can this be done :

First Method

1. Simply copy paste the code below in your funtion.php file and all your images inside the post will be strip off.

function remove_images( $content ) {
   $noimages = preg_replace('/<img[^>]+./','', $content);
   return $noimages ;
}
add_filter( 'the_content', 'remove_images', 100 );

Second Method

$content = get_the_content();
$noimages = preg_replace('/<img[^>]+./','', $content);
echo $noimages;

This will remove every image from the content everywhere.

Facebook Comments
1 0

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 2 =