get_the_content_feed()
Gets the content of the current post in the feed loop. Used in the loop.
This function is a copy of the function the_content(), with the only difference that the text is also processed by the filter the_content_feed, not just the_content.
If the post content for the feed needs to be displayed, use the_content_feed().
Uses: get_the_content()
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
Returns
String. The post content for use in the feed.
Usage
get_the_content_feed( $feed_type );
- $feed_type(string)
Type of feed: rss2 | atom | rss | rdf.
By default, the result of the function get_default_feed() is used, which is almost always - rss2. This value can also be changed via the filter:
$default_feed = apply_filters( 'default_feed', 'rss2' );
Default: null (rss2)
Examples
#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
}
?> #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
- See: get_the_content()
Changelog
| Since 2.9.0 | Introduced. |
get_the_content_feed() get the content feed code WP 6.8.3
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( ']]>', ']]>', $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 );
}