函数文档

the_embed_site_title()

💡 云策文档标注

概述

the_embed_site_title() 函数用于在嵌入模板中输出站点标题的 HTML 标记,包括站点图标和名称,并可通过 embed_site_title_html 过滤器进行自定义。

关键要点

  • 函数生成包含站点图标(32px 和 64px 版本)和站点名称的链接标记
  • 使用 esc_url() 和 esc_html() 确保输出安全
  • 提供 embed_site_title_html 过滤器,允许开发者修改站点标题的 HTML 输出
  • 首次引入于 WordPress 4.5.0 版本

代码示例

function the_embed_site_title() {
    $site_title = sprintf(
        '<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon" /><span>%s</span></a>',
        esc_url( home_url() ),
        esc_url( get_site_icon_url( 32, includes_url( 'images/w-logo-blue.png' ) ) ),
        esc_url( get_site_icon_url( 64, includes_url( 'images/w-logo-blue.png' ) ) ),
        esc_html( get_bloginfo( 'name' ) )
    );

    $site_title = '<div class="wp-embed-site-title">' . $site_title . '</div>';

    echo apply_filters( 'embed_site_title_html', $site_title );
}

注意事项

  • 函数依赖于 get_site_icon_url()、home_url() 和 get_bloginfo() 等核心函数来获取站点数据
  • 输出已包含必要的转义,确保在嵌入上下文中安全使用

📄 原文内容

Prints the necessary markup for the site title in an embed template.

Source

function the_embed_site_title() {
	$site_title = sprintf(
		'<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon" /><span>%s</span></a>',
		esc_url( home_url() ),
		esc_url( get_site_icon_url( 32, includes_url( 'images/w-logo-blue.png' ) ) ),
		esc_url( get_site_icon_url( 64, includes_url( 'images/w-logo-blue.png' ) ) ),
		esc_html( get_bloginfo( 'name' ) )
	);

	$site_title = '<div class="wp-embed-site-title">' . $site_title . '</div>';

	/**
	 * Filters the site title HTML in the embed footer.
	 *
	 * @since 4.4.0
	 *
	 * @param string $site_title The site title HTML.
	 */
	echo apply_filters( 'embed_site_title_html', $site_title );
}

Hooks

apply_filters( ’embed_site_title_html’, string $site_title )

Filters the site title HTML in the embed footer.

Changelog

Version Description
4.5.0 Introduced.