X-Redirect-By
header allows applications to identify themselves when they’re doing a redirect. wp_redirect() function adds this header. You can pass X-Redirect-By
header value in third argument to wp_redirect() function. Argument is optional and default value is WordPress.
wp_redirect( string $location, int $status = 302, string $x_redirect_by = ‘WordPress’ ): bool
wp_safe_redirect( string $location, int $status = 302, string $x_redirect_by = ‘WordPress’ ): bool
# The `$x_redirect_by` parameter was added in WordPress version 5.1.0
# WordPress Core
x-redirect-by: WordPress
X-Redirect-By
header is important because it helps to identify what application performing redirection. Following are the few examples of plugins.
# Safe Redirect Manager Plugin
x-redirect-by: Safe Redirect Manager
# Redirection Plugin
x-redirect-by: redirection
# Yoast SEO Premium Plugin
x-redirect-by: Yoast SEO Premium
So, next time if you are using wp_redirect() or wp_safe_redirect() functions, make sure you pass third argument to add X-Redirect-By
header for your application. Header value could be either your plugin or theme name or if you can be more specific than it would be good. For example, unique-prefix-old-legacy-url-redirect
x_redirect_by hook allows to filter X-Redirect-By
header.
/**
* Filters the X-Redirect-By header.
*
* Allows applications to identify themselves when they're doing a redirect.
*
* @since 5.1.0
*
* @param string $x_redirect_by The application doing the redirect.
* @param int $status Status code to use.
* @param string $location The path to redirect to.
*/
$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
Leave a Reply