Set HTTP status code 401
-
Hi there,
currently, if the password protection page is displayed, it answers with an HTTP status code 200. However, for a protected page, this is wrong and also may result in problems regarding SEO. Switching to status code 401 would be better.
If you implement this, it would also be great to make it filterable (since I use some logic to bypass the password protection and then would also need to change the status code).
Currently, my implementation for the status code looks like this:
/**
* Set an HTTP status code of 401, if password protection is enabled.
*/
function set_status_code(): void {
if ( ! \class_exists( 'Password_Protected' ) ) {
return;
}
if ( my_condition ) {
return;
}
$password_protected = new \Password_Protected();
if ( $password_protected->is_active() ) {
\status_header( 401 );
}
}
\add_action( 'wp', 'set_status_code' );Best regards,
Matthias
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Set HTTP status code 401’ is closed to new replies.