Site logo

Archived topic

How to Change the "Password Protected Page"?

3 replies · Started by Adam on November 7, 2021

Viewing posts 1–4 of 4

Hi, I have some posts protected by a password. Now, when you scroll through a category or the main page where the password-protected post is, it reads:

"This content is password protected. To view it please enter your password below:"

Is it possible to change this text? I'd like to add more context to that message, for example how to get this password.

When I tried to edit the password-protected post, I could only edit the message.

Thank you

Hi there,

not easily... WP provides the the_password_form filter which would allow you to modify the password protect form:

https://developer.wordpress.org/reference/hooks/the_password_form/

You could also create a Block Element to display additional content on the page:

https://docs.generatepress.com/article/block-element-overview/

Whilst your creating the block, check the browser URL to get the ID of the block element.

The Display Rule Location you would leave empty then we can use a PHP Snippet to display it if the page is password protected:

add_filter( 'generate_element_display', function( $display, $element_id ) {
    if ( 100 === $element_id && !empty($post->post_password) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );

The 100 needs to be updated to the ID of the Block Element.

Thanks David,
yeah, that doesn't sound easy but at least now I know not trying to change it. Thanks for mentioning the blocks. I'll figure out some workaround.

No problem :)

This archived topic is closed to new replies.