- This topic has 6 replies, 3 voices, and was last updated 7 years ago by Tom.
-
AuthorPosts
-
February 9, 2017 at 12:39 pm #276697_blank
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!
TammyFebruary 9, 2017 at 7:06 pm #276809TomLead DeveloperLead DeveloperEditing 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/
March 26, 2017 at 8:13 am #297539TimHello 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 dateMarch 26, 2017 at 9:56 am #297581TomLead DeveloperLead DeveloperTypically hooks/filters will never changes, as WP needs to keep backwards compatibility between versions.
How are you adding the code?
March 28, 2017 at 2:48 pm #298665TimI am using
Generate Simple PHP
March 28, 2017 at 8:05 pm #298744TimHey, 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
March 28, 2017 at 10:12 pm #298772TomLead DeveloperLead DeveloperAwesome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.