get_the_content_feed()WP 2.9.0

Retrieve the post content for feeds.

1 time — 0.001937 sec (very slow) | 50000 times — 8.21 sec (fast) | PHP 7.0.8, WP 4.6.1
Hooks from the function

Return

String. The filtered content.

Usage

get_the_content_feed( $feed_type );
$feed_type(string)
The type of feed. rss2 | atom | rss | rdf
Default: null

Examples

0

#1 Display content in the <item> tag

<?php
$content = get_the_content_feed('rss2');
if( strlen( $content ) > 0 ){
	?>
	<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
	<?php }else{ ?>
	<content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
	<?php
}
?>
0

#2 Full code of <item> tag

Taken from file: wp-includes/feed-rss2.php

<?php
/**
 * Fires at the end of the RSS2 Feed Header.
 *
 * @since 2.0.0
 */
do_action( 'rss2_head');

while( have_posts() ){
	the_post();
	?>
	<item>
		<title><?php the_title_rss() ?></title>
		<link><?php the_permalink_rss() ?></link>
		<?php if ( get_comments_number() || comments_open() ){ ?>
			<comments><?php comments_link_feed(); ?></comments>
		<?php } ?>

		<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><![CDATA[<?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 $content = get_the_content_feed('rss2'); ?>
			<?php if ( strlen( $content ) > 0 ){ ?>
				<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
			<?php }else{ ?>
				<content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
			<?php } ?>
		<?php } ?>

		<?php if ( get_comments_number() || comments_open() ){ ?>
			<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 } ?>

		<?php rss_enclosure(); ?>
		<?php
		/**
		 * Fires at the end of each RSS2 feed item.
		 *
		 * @since 2.0.0
		 */
		do_action( 'rss2_item' );
		?>
	</item>
	<?php
}
?>

Notes

Changelog

Since 2.9.0 Introduced.

get_the_content_feed() code WP 6.5.2

function get_the_content_feed( $feed_type = null ) {
	if ( ! $feed_type ) {
		$feed_type = get_default_feed();
	}

	/** This filter is documented in wp-includes/post-template.php */
	$content = apply_filters( 'the_content', get_the_content() );
	$content = str_replace( ']]>', ']]&gt;', $content );

	/**
	 * Filters the post content for use in feeds.
	 *
	 * @since 2.9.0
	 *
	 * @param string $content   The current post content.
	 * @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'.
	 *                          Default 'rss2'.
	 */
	return apply_filters( 'the_content_feed', $content, $feed_type );
}