logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$20
Remove HTML from post content inside feed template page

Hey,
I'm trying to create a custom feed template based on the original WordPress feed file. One important element of that feed is showing plain text (stripping image, video, and other html) post content. Also, it needs to display full post not an excerpt. I couldn't find any good resources that would help me accomplish this. So I would really appreciate your help guys. To make life easier, here's the file:

<?php
/**
* RSS2 Feed Template for displaying RSS2 Posts feed.
*
* @package WordPress
*/

header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$more = 1;

echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>

<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
<?php do_action('rss2_ns'); ?>
>

<channel>
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss("description") ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language><?php echo get_option('rss_language'); ?></language>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php while( have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss() ?></title>
<link><?php the_permalink_rss() ?></link>
<comments><?php comments_link_feed(); ?></comments>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<dc:creator><?php the_author() ?></dc:creator>
<?php the_category_rss('rss2') ?>

<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if (get_option('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php if ( strlen( $post->post_content ) > 0 ) : ?>
<content:encoded><![CDATA[<?php the_content_feed('rss2') ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<?php endif; ?>
<?php endif; ?>
<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss>
<slash:comments><?php echo get_comments_number(); ?></slash:comments>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>


Thanks.

This question has been answered.

Viktor Nagornyy | 07/06/11 at 4:17pm Edit


(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    07/06/11
    4:58pm
    Julio Potier says:

    Hello

    you can add an action to the_excerpt_rss() like this :

    add_action( 'the_excerpt_rss', 'myfct' );

    and myfct is :
    function myfct( $content ) // $content not used because contains excerpt content
    {
    global $post;
    return strip_tags( $post->post_content );
    }


    See you

    • 07/06/11 5:06pm

      Viktor Nagornyy says:

      Does this go inside the file or in function.php?

      Thanks for replying.

    • 07/06/11 5:09pm

      Julio Potier says:

      functions.php is a good place

    • 07/06/11 5:11pm

      Viktor Nagornyy says:

      Will this affect all feeds? How do I localize it to this particular feed template?

    • 07/06/11 5:12pm

      Julio Potier says:

      in functions.php > all rss
      in the template file > this rss template

    • 07/06/11 6:01pm

      Viktor Nagornyy says:

      Where exactly would this go inside feed template file I posted above without breaking it? Thanks.

    • 07/06/11 6:04pm

      Julio Potier says:

      First line, no problem :)

  • avatar
    Last edited:
    07/06/11
    5:01pm
    Joshua Nelson says:

    Have you checked out Yahoo! Pipes? That's what I use when taking a feed and editing the content. You can combine, filter, cut, truncate (and so much more) and then create a new rss feed from the original pretty easily. You can find walkthroughs for doing what you want online, too long to place here. Then you can take that rss feed and place it on your site or hook it up with a service like feedburner. I could probably build you one, too.

    Are you trying to edit your default feed to do this, though? Are you looking to build it into your wordpress blog as a plugin or native function?

    Yahoo Pipes might be easier and quicker to put together, but then it won't be native to your wordpress install. Pluses and minuses with that. If you want it to be native and effect your actual feed (instead of being a separate feed), then I would try Julio's answer.

    Previous versions of this answer: 07/06/11 at 5:01pm

    • 07/06/11 5:08pm

      Viktor Nagornyy says:

      I'm using Feed Wrangler plugin which creates custom feeds with custom php templates. Just wanted to keep it within WP, but if it won't work I'll Pipe it. Thanks for reply.

  • avatar
    Last edited:
    07/06/11
    5:20pm
    Svilen Popov says:

    Replace the <?php the_excerpt_rss() ?> in your code with the following one

    <?php echo strip_tags(get_the_content_feed('rss2')); ?>

    Previous versions of this answer: 07/06/11 at 5:20pm

This question has expired.



Viktor Nagornyy voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.