钩子文档

the_content_feed

💡 云策文档标注

概述

the_content_feed 是一个 WordPress 过滤器,用于在内容从数据库检索后、发送到 RSS 阅读器前,过滤文章内容以供 feed 使用。它允许开发者修改 feed 中的内容输出。

关键要点

  • 过滤器名称:the_content_feed
  • 参数:$content(当前文章内容字符串)、$feed_type(feed 类型,如 'rss2' 或 'atom',默认 'rss2')
  • 作用时机:在 the_content 钩子过滤后,feed 输出前
  • 回调函数必须返回处理后的内容,否则可能导致 feed 显示空白或插件错误
  • 相关函数:get_the_content_feed()

代码示例

add_filter( "the_content_feed", "plugin_function_name" );

/**
* @param  $content Content of post
* @return string
*/
function plugin_function_name($content)
{
   $content .= 'Total of '.str_word_count($content).' words.';
   return $content;
}

注意事项

确保回调函数正确返回内容,以避免 feed 问题。


📄 原文内容

Filters the post content for use in feeds.

Parameters

$contentstring
The current post content.
$feed_typestring
Type of feed. Possible values include 'rss2', 'atom'.
Default 'rss2'.

More Information

  • The “the_content_feed” filter is used to filter the content of the post after it is retrieved from the database and filtered by “the_content” hook and before it is sent to RSS reader (or browser).
  • The filter callback function must return the content after it is finished processing, or feed readers will see a blank item and other plugins also filtering the feed content may generate errors.

Source

return apply_filters( 'the_content_feed', $content, $feed_type );

Changelog

Version Description
2.9.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example Migrated from Codex:

    Count the number of words in $content, then add the count number as paragraph to the bottom of $content.

    add_filter( "the_content_feed", "plugin_function_name" );
    
    /**
    * @param  $content Content of post
    * @return string
    */
    function plugin_function_name($content)
    {
       $content .= '<p>Total of '.str_word_count($content).' words.</p>';
       return $content;
    }