redirect_canonical

Filters the canonical redirect URL.

Description

apply_filters( 'redirect_canonical', (string) $redirect_url, (string) $requested_url ); 

Returning false to this filter will cancel the redirect.

Parameters (2)

0. $redirect_url (string)
The redirect url.
1. $requested_url (string)
The requested url.

Usage

To run the hook, copy the example below.
  1. $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url ); 
  2.  
  3. if ( !empty( $redirect_url ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the redirect_canonical callback 
  2. function filter_redirect_canonical( $redirect_url, $requested_url ) { 
  3. // make filter magic happen here... 
  4. return $redirect_url
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'redirect_canonical', 'filter_redirect_canonical', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'redirect_canonical', 'filter_redirect_canonical', 10, 2 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/canonical.php  
  1. $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );