W3cubDocs

/WordPress

wp_referer_field( bool $display = true ): string

Retrieves or displays referer hidden field for forms.

Description

The referer link is the current Request URI from the server super global. The input name is ‘_wp_http_referer’, in case you wanted to check manually.

Parameters

$displaybooloptional
Whether to echo or return the referer field.

Default:true

Return

string Referer field HTML markup.

Source

function wp_referer_field( $display = true ) {
	$request_url   = remove_query_arg( '_wp_http_referer' );
	$referer_field = '<input type="hidden" name="_wp_http_referer" value="' . esc_url( $request_url ) . '" />';

	if ( $display ) {
		echo $referer_field;
	}

	return $referer_field;
}

Changelog

Version Description
2.0.4 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_referer_field