Easy and simple:
1 |
$content = preg_replace("/<img[^>]+\>/i", " ", $content); |
This came handy when I had a wordpress theme that was showing on the homepage both the featured image and the image in the beginning of the post’s content and I wanted to remove the images which are part of the content.
What I did:
In content.php (the template file which shows the homepage content –
Instead of the default:
1 |
the_content(''); |
I used:
1 2 3 4 |
$content = get_the_content(''); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo(preg_replace("/<img[^>]+\>/i", " ", $content)); |