I'd like to remove the image from my RSS feed and add some "Read more" text. The code I have is

echo strip_tags(the_excerpt_rss(), '<p><a>') . 
'<a href="' . the_permalink_rss() . '">Read more</a> at ' . 

But when this is run, I still have the image and the extra text is weirdly formatted. eg:

<content:encoded>![CDATA{ <img src="{imgpath}" alt="{imgAlt}"/>{postExcerpt}...{link}{link}<a href="">Read more</a> at]]>

Why does this happen? I followed the instructions at Remove images from get_the_excerpt but it still shows images and the extra text is formatted strangely.


Note that the_permalink_rss() and the_excerpt_rss() do echo the output, not return it.

With your current snippet, replace the_excerpt_rss() with:

apply_filters( 'the_excerpt_rss', get_the_excerpt() );

and replace the_permalink_rss() with:

esc_url( apply_filters( 'the_permalink_rss', get_permalink() ) );

You could also use:

    <?php  the_excerpt_rss(); ?> 
    <a href="<?php the_permalink_rss(); ?>">
        <?php esc_html_e( 'Read more', 'mydomain' );?>
    <?php esc_html_e( 'at', 'mydomain' );?>
    <?php the_permalink_rss(); ?>

where you strip the RSS excerpt through the the_excerpt_rss filter or use the above approach to get the excerpt output to strip it.

You could also try using printf with:

<content:encoded><![CDATA[%s <a href="%s">%s</a> %s %s]]></content:encoded>


  • Final, WORKING, code is: <content:encoded><![CDATA[ <?php echo strip_tags(apply_filters( 'the_excerpt_rss', get_the_excerpt() ), '<p><a>'); ?> <a href="<?php the_permalink_rss(); ?>"> <?php esc_html_e( 'Read more', 'mydomain' );?> </a> <?php esc_html_e( ' at', 'mydomain' );?> <?php the_permalink_rss(); ?> ]]></content:encoded> Thanks so much, @birgire.
    – ThatGuy
    Nov 7 '16 at 23:13
  • Glad to hear you got it working, yes there are few ways, I think it's like returning null, when functions only echo the output, so your previous example in the question, was like strip_tags(null).@EddieS
    – birgire
    Nov 7 '16 at 23:33

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.