wp_original_referer_field() WordPress Function

The wp_original_referer_field() function is used to retrieve the original referer field for a given Wordpress user. This can be useful for retrieving information about where a user came from before landing on your site.

wp_original_referer_field( bool $echo = true, string $jump_back_to = 'current' ) #

Retrieve or display original referer hidden field for forms.


Description

The input name is ‘_wp_original_http_referer’ and will be either the same value of wp_referer_field(), if that was posted already or it will be the current page, if it doesn’t exist.


Top ↑

Parameters

$echo

(bool)(Optional) Whether to echo the original http referer.

Default value: true

$jump_back_to

(string)(Optional) Can be 'previous' or page you want to jump back to.

Default value: 'current'


Top ↑

Return

(string) Original referer field.


Top ↑

Source

File: wp-includes/functions.php

function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
	$ref = wp_get_original_referer();

	if ( ! $ref ) {
		$ref = ( 'previous' === $jump_back_to ) ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
	}

	$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';

	if ( $echo ) {
		echo $orig_referer_field;
	}

	return $orig_referer_field;
}


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