函数文档

rss2_site_icon()

💡 云策文档标注

概述

rss2_site_icon() 是一个 WordPress 函数,用于在 RSS2 源中显示站点图标。它通过获取站点图标 URL 和相关信息,输出符合 RSS2 规范的 XML 标签。

关键要点

  • 函数 rss2_site_icon() 在 RSS2 源中输出站点图标,包括 URL、标题和链接。
  • 它使用 get_site_icon_url() 获取图标 URL,并默认尺寸为 32x32 像素。
  • 函数内部处理 RSS 标题,优先使用 get_wp_title_rss(),若为空则回退到 get_bloginfo_rss('name')。
  • 输出前通过 convert_chars() 转换特殊字符以确保 XML 兼容性。
  • 此函数自 WordPress 4.3.0 版本引入。

代码示例

function rss2_site_icon() {
    $rss_title = get_wp_title_rss();
    if ( empty( $rss_title ) ) {
        $rss_title = get_bloginfo_rss( 'name' );
    }

    $url = get_site_icon_url( 32 );
    if ( $url ) {
        echo '

    ' . convert_chars( $url ) . '
    ' . $rss_title . '
    ' . get_bloginfo_rss( 'url' ) . '
    32
    32
 ' . "n";
    }
}

注意事项

  • 确保站点图标已设置,否则 get_site_icon_url() 可能返回空值,导致无输出。
  • 输出格式遵循 RSS2 规范,开发者可自定义或扩展此函数以满足特定需求。
  • 相关函数如 get_site_icon_url()、convert_chars() 等位于不同核心文件中,需注意依赖关系。

📄 原文内容

Displays Site Icon in RSS2.

Source

function rss2_site_icon() {
	$rss_title = get_wp_title_rss();
	if ( empty( $rss_title ) ) {
		$rss_title = get_bloginfo_rss( 'name' );
	}

	$url = get_site_icon_url( 32 );
	if ( $url ) {
		echo '
<image>
	<url>' . convert_chars( $url ) . '</url>
	<title>' . $rss_title . '</title>
	<link>' . get_bloginfo_rss( 'url' ) . '</link>
	<width>32</width>
	<height>32</height>
</image> ' . "n";
	}
}

Changelog

Version Description
4.3.0 Introduced.