函数文档

get_self_link()

💡 云策文档标注

概述

get_self_link() 函数用于返回当前显示 feed 的链接,适用于 WordPress 开发者处理 feed 相关功能。该函数通过解析站点 URL 和请求 URI 来生成正确的 atom:self 元素链接。

关键要点

  • 返回当前显示 feed 的链接,用于 atom:self 元素
  • 基于 home_url() 和 $_SERVER['REQUEST_URI'] 构建链接
  • 使用 set_url_scheme() 设置 URL 方案,确保链接正确性
  • 相关函数包括 self_link() 用于安全显示链接
  • 自 WordPress 5.3.0 版本引入

代码示例

function get_self_link() {
    $parsed = parse_url( home_url() );

    $domain = $parsed['host'];
    if ( isset( $parsed['port'] ) ) {
        $domain .= ':' . $parsed['port'];
    }

    return set_url_scheme( 'http://' . $domain . wp_unslash( $_SERVER['REQUEST_URI'] ) );
}

📄 原文内容

Returns the link for the currently displayed feed.

Return

string Correct link for the atom:self element.

Source

function get_self_link() {
	$parsed = parse_url( home_url() );

	$domain = $parsed['host'];
	if ( isset( $parsed['port'] ) ) {
		$domain .= ':' . $parsed['port'];
	}

	return set_url_scheme( 'http://' . $domain . wp_unslash( $_SERVER['REQUEST_URI'] ) );
}

Changelog

Version Description
5.3.0 Introduced.