get_self_link()WP 5.3.0

Returns the link for the currently displayed feed.

1 time — 0.0135138 sec (extremely slow) | 50000 times — 0.80 sec (very fast)

No Hooks.

Return

String. Correct link for the atom:self element.

Usage

get_self_link();

Examples

0

#1 Demo of what the function outputs on different pages

In short, the function always outputs exactly what is currently in the browser line. If it is not a browser request, it will output the URL to which the request was made.

echo get_self_link();

// Home: http://wptest.loc/
// Post page: http://wptest.loc/template-sticky/
// Admin (home): http://wptest.loc/wp-admin/
// Category (with custom parameters): http://wptest.loc/category/uncategorized/?foo=bar

Changelog

Since 5.3.0 Introduced.

get_self_link() code WP 6.1.1

function get_self_link() {
	$host = parse_url( home_url() );
	return set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) );
}