wp_referer_field() WordPress Function

The wp_referer_field function is used to create a hidden form field with the current URL of the page. This is used to help prevent spam by allowing WordPress to know where a form submission came from.

wp_referer_field( bool $echo = true ) #

Retrieve or display 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.


Top ↑

Parameters

$echo

(bool)(Optional) Whether to echo or return the referer field.

Default value: true


Top ↑

Return

(string) Referer field HTML markup.


Top ↑

Source

File: wp-includes/functions.php

function wp_referer_field( $echo = true ) {
	$referer_field = '<input type="hidden" name="_wp_http_referer" value="' . esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';

	if ( $echo ) {
		echo $referer_field;
	}

	return $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