Archived topic
Edit Password Protected Pages
6 replies · Started by _blank on February 9, 2017
Hi Tom,
Password protected pages are an excellent way to entice visitors to sign up for my ezine. Is there a way to edit the text in these pages, right before the visitor enters the password? And if so, where? Or, is there a plugin for this?
Thank you!
Tammy
Editing the text with the core password protected area would involve a decent amount of PHP as far as I can see.
Maybe a plugin like this might be better to work with? https://en-ca.wordpress.org/plugins/content-protector/
Hello Tom, I got the following from here:
http://stackoverflow.com/questions/28105822/style-wordpress-protected-posts#
i) If you want to add text to your password form, you can use the following:
add_action( 'the_password_form', 'rob_the_password_form' );
function rob_the_password_form( $output )
{
$before = ' Before '; // Modify this to your needs!
$after = ' After '; // Modify this to your needs!
return $before . $output . $after;
}
ii) If you want to modify the HTML form directly, you can override it with:
add_filter( 'the_password_form', 'rob_override_the_password_form' );
function rob_override_the_password_form( $form = '' ) {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$form = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $form;
}
To change the default Protected: title prefix, you can use:
add_filter( 'protected_title_format', 'rob_protected_title_format' );
function rob_protected_title_format( $format )
{
$format = __( ' Members only! %s ' ); // Modify this to your needs!
return $format;
}
I tried them but they do not work, I was wondering if the hooks they are using are up to date
Typically hooks/filters will never changes, as WP needs to keep backwards compatibility between versions.
How are you adding the code?
I am using Generate Simple PHP
Hey, The code above is working! maybe my caching plugin was not updating the pages so it only seemed like it was not working
Thanks for responding
Awesome :)