My feed uses the excerpt, and I want to remove a line of code containing an image.

Example format is...

<img class="pagehead" src="/graphics/magazine/307/1.jpg" alt="" />


Answering my own question, I'll add this in the hope it'll be useful to someone...

Whilst waiting for answers, I found a solution which seems to work fine.

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

You can customize your feed like any other template and use the_excerpt_rss function:

<?php the_excerpt_rss( $cut, $encode_html ); ?>

Or maybe use PHP strip_tags function :

// Autorise <p> et <a>
echo strip_tags( $text, '<p><a>' );
  • Thanks. And that'll remove the whole line - everything between the html brackets? – gulliver Sep 6 '16 at 18:58
  • Strip_tags function will remove html & php tags in string, not the texts in it. – Dexter0015 Sep 7 '16 at 7:55
  • Thanks. I couldn't get the-excerpt-rss to accept parameters, so strip_tags looks to be a better option - thanks for the useful link, it'll be helpful. – gulliver Sep 8 '16 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.