WordPress.org

Codex

Function Reference/wp get referer

Contents

Description

Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively.

Usage

<?php wp_get_referer() ?>

Parameters

None.

Return Values

(string|boolean) 
False on failure. Referer URL on success. If page "refered" (form posted) to itself, returns false (because $_SERVER['HTTP_REFERER'] == $_REQUEST['_wp_http_referer'])

Examples

<?php 
if ( wp_get_referer() )
{
    
wp_safe_redirectwp_get_referer() );
}
else
{
    
wp_safe_redirectget_home_url() );
}
?>

Notes

  • HTTP referer is a server variable. 'referer' is deliberately misspelled.

Change Log

Since: 2.0.4

Source File

wp_get_referer() is located in wp-includes/functions.php.

Related

See also index of Function Reference and index of Template Tags.