Redirection can be extended and customised using WordPress actions and filters.
To use these you will need to add the hooks to your own plugin or to your theme’s functions.php
file.
Support is provided for the plugin, not for custom PHP code. It is your responsibility to ensure that the PHP code is correct and does what you need. There are many, many, websites detailing how to code for WordPress.
Filters
A WordPress filter returns data, and is used in Redirection to modify various bits of data. To use a filter:
add_filter( 'filter_name', function( $param1, $param2 ) {
return 'your custom value';
}, 10, 2 );
Full details can be found on the WordPress filter page.
Request Information
The following WordPress filters are available for customisation of a server requests.
redirection_request_url
Modify the requested URL
$url
redirection_request_agent
Modify the requesting client’s user agent
$agent
redirection_request_referrer
Modify the requesting client’s referrer
$referrer
redirection_request_ip
Modify the requesting client’s IP address
$ip
redirection_request_cookie
Modify the requesting client’s cookie value
$value
$name
redirection_request_header
Modify a header value from the requesting client
$value
$name
redirection_request_headers
Return all the client HTTP headers
$headers
header => value
redirection_request_headers_ignore
Return a list of header values that are ignored
$headers
redirection_request_method
Return the current HTTP request method
$method
redirection_request_server
Return the current server name
$server
redirection_request_accept_language
Return the client’s
accept-language
$lang
Logging
The following WordPress filters are available for customisation of logged data:
redirection_404_data
Data to be inserted into the 404 table
$data
false
to skip loggingredirection_log_data
Data to be inserted into the log table
$data
false
to skip loggingredirection_log_404
Determine if the current 404 page should be logged
$log
true
if it should be logged, false
otherwiseredirection_redirect_counter
Determine if a redirect should increase the hit counter
$inc
true
if it should, false
otherwiseRedirect source and target
redirection_url_source
The original URL used before matching a request
$url
false
to stop a redirectionredirection_url_target
The target URL after a request has been matched (and after any regular expression captures have been replaced)
$url
false
to stop a redirectionActions
redirection_log
Fired when the page is logged
$log
redirection_do_nothing
Fired when a ‘do nothing’ action happens
redirection_remove_existing
Fired when a post changes permalink and we need to clear existing redirects that might affect it
redirection_monitor_created
Fired when a redirect is created for a monitor post type. Supplied with the new redirect, old post, and post ID
redirection_redirect_updated
Action fired when a redirect is updated or created
redirection_redirect_deleted
Action fired when a redirect is deleted
Management Filters
redirection_permalink_changed
Return
true
if a post’s permalink has changed, or false otherwisetrue
if changed, false
otherwisetrue
or false
redirection_monitor_types
Modify what post types are monitored by Redirection
redirection_create_redirect
Modify redirect data before a redirect is created
redirection_update_redirect
Modify redirect data before a redirect is updated
redirection_validate_redirect
Validate data for a redirect
red_default_options
Modify the default options
redirection_save_options
Modify options before they are saved
Additionally, if the target URL is a number without any slashes then Redirection will treat it as a post ID and redirect to the full URL for that post.
HTTP Headers
redirection_header_site
– Array of HTTP headers that Redirection is adding from the ‘site’ locationredirection_header_redirect
– Array of HTTP headers that Redirection is adding from the ‘redirect’ location (will include those from ‘site’)