wp_get_raw_referer()
Gets the referer (referer) URL. A wrapper for $_SERVER['HTTP_REFERER'].
The function first checks for the presence of the referer in $_REQUEST['_wp_http_referer'], if it is not there, it takes the referer as usual from $_SERVER['HTTP_REFERER'].
Use wp_get_referer() when you need to get only the internal referer link - a referer link only from the current site (if not from the current site, then get an empty string instead of the URL)
Used By: wp_get_referer()
No Hooks.
Returns
String|false. URL — if the referer exists. false — if there is no referer.
Usage
$referer = wp_get_raw_referer();
Examples
#1 Check if there is a referrer link
Suppose we were on page http://example.com/foo and went to page http://example.com/bar where the following code is triggered:
$referer = wp_get_raw_referer();
if( $referer ){
echo $referer;
}
On the screen we will see the URL of the page we came from: http://example.com/foo.
Changelog
| Since 4.5.0 | Introduced. |
wp_get_raw_referer() wp get raw referer code WP 6.8.3
function wp_get_raw_referer() {
if ( ! empty( $_REQUEST['_wp_http_referer'] ) && is_string( $_REQUEST['_wp_http_referer'] ) ) {
return wp_unslash( $_REQUEST['_wp_http_referer'] );
} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
return wp_unslash( $_SERVER['HTTP_REFERER'] );
}
return false;
}