[Resolved] Edit Password Protected Pages

Home Forums Support [Resolved] Edit Password Protected Pages

Home Forums Support Edit Password Protected Pages

  • This topic has 6 replies, 3 voices, and was last updated 7 years ago by Tom.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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!
    Tammy

    #276809
    Tom
    Lead Developer
    Lead Developer

    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/

    #297539
    Tim

    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

    #297581
    Tom
    Lead Developer
    Lead Developer

    Typically hooks/filters will never changes, as WP needs to keep backwards compatibility between versions.

    How are you adding the code?

    #298665
    Tim

    I am using Generate Simple PHP

    #298744
    Tim

    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

    #298772
    Tom
    Lead Developer
    Lead Developer

    Awesome 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.