• 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)
  • Plugin Support Muhammad Usama Azad

    (@usamaazad99)

    Hi @kittmedia ,

    I hope you are doing well,

    Thank you for reaching out to the WP Experts Support Team. I’m glad to assist you today.

    I’ll discuss your query with our Technical Team and get back to you shortly.

    We appreciate your patience.

    Thanks & Regards,
    WP Experts Support Team

    Plugin Support Muhammad Usama Azad

    (@usamaazad99)

    Hi @kittmedia ,

    I hope you’re doing well!

    Thank you so much for sharing your idea and showing how you implemented it — we truly appreciate your input.

    I just wanted to let you know that we’ve noted your suggestion, and we plan to include it in our upcoming release.

    Thanks again for your valuable feedback!

    Best regards,
    WP Experts Support Team

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Set HTTP status code 401’ is closed to new replies.