Archived topic
How to change text in password protected page
5 replies · Started by anabella on October 7, 2022
Hi. On the password protected page, I need to change the text: instead of having the default "this content is password protected. To view it please enter the password below", I need it to say "send me an email at example@myemail.com and I will give you the password"
Is there an easy way of achieving that?
Thanks
Hi there,
see my reply here:
https://generatepress.com/forums/topic/how-to-change-the-password-protected-page/#post-1994913
I would suggest trying the Block Element method to insert your custom message. Let me know
Thanks David.
I am trying the Block Element method but it's not working.
1. I created the block by going to Elements > Create new > Block > I added my content. Then > location: I left that empty > Element type: Hook. The URL looks like this: /post.php?post=2402&action=edit&lang=es
I am assuming that 2402 is the ID of the block element?
2. The I added your code using the plugin Code Snippets:
add_filter( 'generate_element_display', function( $display, $element_id ) {
if ( 2402 === $element_id && !empty($post->post_password) ) {
$display = true;
}
return $display;
}, 10, 2 );
Could you please let me know what I'm doing wrong?
Thanks!
1. correct 2402 is the ID.
What Hook did you select ?
In the HOOK NAME drop-down, I tried all the options that are in the CONTENT section (so, inside_site_container, site_container, before_main_content, etc). Unfortunately none of them worked.
Ok, so change the Element Type to: Page Hero
And set the Display Rules to All Posts and All Pages ( or wherever you're using password protects ).
Then change the snippet to:
add_filter( 'generate_element_display', function( $display, $element_id ) {
if ( 100 === $element_id && empty($post->post_password) ) {
$display = false;
}
return $display;
}, 10, 2 );
That way the element is set to show everywhere, and snippet will remove it if there is NO password on the post.