get_self_link()
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
#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() get self link code WP 6.6.2
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'] ) ); }