Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Remove HTML from post content inside feed template page WordPress

  • SOLVED

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.

Answers (3)

2011-07-06

Svilen Popov answers:

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

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

2011-07-06

Julio Potier answers:

Hello

you can add an action to <em>the_excerpt_rss()</em> like this :
add_action( 'the_excerpt_rss', 'myfct' );
and <em>myfct</em> is :
function myfct( $content ) // $content not used because contains excerpt content
{
global $post;
return strip_tags( $post->post_content );
}


See you


Viktor Nagornyy comments:

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

Thanks for replying.


Julio Potier comments:

functions.php is a good place


Viktor Nagornyy comments:

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


Julio Potier comments:

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


Viktor Nagornyy comments:

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


Julio Potier comments:

First line, no problem :)

2011-07-06

Joshua Nelson answers:

Have you checked out [[LINK href="http://pipes.yahoo.com"]]Yahoo! Pipes[[/LINK]]? 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.


Viktor Nagornyy comments:

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.