wp_get_referer() WordPress Function

The wp_get_referer() function is used to retrieve the URL of the previous page the user was on. This is useful for finding out where a user came from before landing on the current page.

wp_get_referer() #

Retrieve referer from ‘_wp_http_referer’ or HTTP referer.


Description

If it’s the same as the current request URL, will return false.


Top ↑

Return

(string|false) Referer URL on success, false on failure.


Top ↑

More Information

HTTP referer is a server variable. ‘referer’ is deliberately misspelled.

If page “refered” (form posted) to itself, returns false (because $_SERVER[‘HTTP_REFERER’] == $_REQUEST[‘_wp_http_referer’])


Top ↑

Source

File: wp-includes/functions.php

function wp_get_referer() {
	if ( ! function_exists( 'wp_validate_redirect' ) ) {
		return false;
	}

	$ref = wp_get_raw_referer();

	if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref && home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref ) {
		return wp_validate_redirect( $ref, false );
	}

	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.4Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More