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_urlModify the requested URL
$urlredirection_request_agentModify the requesting client’s user agent
$agentredirection_request_referrerModify the requesting client’s referrer
$referrerredirection_request_ipModify the requesting client’s IP address
$ipredirection_request_cookieModify the requesting client’s cookie value
$value$nameredirection_request_headerModify a header value from the requesting client
$value$nameredirection_request_headersReturn all the client HTTP headers
$headersheader => valueredirection_request_headers_ignoreReturn a list of header values that are ignored
$headersredirection_request_methodReturn the current HTTP request method
$methodredirection_request_serverReturn the current server name
$serverredirection_request_accept_languageReturn the client’s
accept-language$langLogging
The following WordPress filters are available for customisation of logged data:
redirection_404_dataData to be inserted into the 404 table
$datafalse to skip loggingredirection_log_dataData to be inserted into the log table
$datafalse to skip loggingredirection_log_404Determine if the current 404 page should be logged
$logtrue if it should be logged, false otherwiseredirection_redirect_counterDetermine if a redirect should increase the hit counter
$inctrue if it should, false otherwiseRedirect source and target
redirection_url_sourceThe original URL used before matching a request
$urlfalse to stop a redirectionredirection_url_targetThe target URL after a request has been matched (and after any regular expression captures have been replaced)
$urlfalse to stop a redirectionActions
redirection_logFired when the page is logged
$logredirection_do_nothingFired when a ‘do nothing’ action happens
redirection_remove_existingFired when a post changes permalink and we need to clear existing redirects that might affect it
redirection_monitor_createdFired when a redirect is created for a monitor post type. Supplied with the new redirect, old post, and post ID
redirection_redirect_updatedAction fired when a redirect is updated or created
redirection_redirect_deletedAction fired when a redirect is deleted
Management Filters
redirection_permalink_changedReturn
true if a post’s permalink has changed, or false otherwisetrue if changed, false otherwisetrue or falseredirection_monitor_typesModify what post types are monitored by Redirection
redirection_create_redirectModify redirect data before a redirect is created
redirection_update_redirectModify redirect data before a redirect is updated
redirection_validate_redirectValidate data for a redirect
red_default_optionsModify the default options
redirection_save_optionsModify 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’)