18 Responses

  1. The Frosty @WPCult
    The Frosty @WPCult June 24, 2009 at 11:27 am |

    That’s really awesome. Short and sweet!

    Reply
  2. Show the post password form for the_excerpt in a WordPress — WPCult
  3. Adam W. Warner
    Adam W. Warner June 24, 2009 at 2:39 pm |

    Nice little trick Justin:)

    Reply
  4. johnbillion
    johnbillion June 24, 2009 at 4:51 pm |

    Nice tip Justin. Will the visitor be automatically redirected to the single post or will they be returned back to the page where they entered the password?

    Reply
  5. J Mehmett
    J Mehmett June 27, 2009 at 12:42 am |

    Hi, Justin. I had a comment on this topic with experimental code on it. It seems as your spam filter ate it again :(

    Reply
  6. Danny
    Danny June 30, 2009 at 5:41 am |

    Hey Justin, is this code referred to WordPress 2.7? I ask you because in 2.8 it works without editing functions.php… Thanks in advance!

    Reply
  7. J Mehmett
    J Mehmett July 1, 2009 at 12:37 am |

    Justin, I don’t know, why its not save to post a code in the comments area. It goes to the moderation queue or it gets eaten by Akismet :(

    Back to the comment, it was nothing but a possibility of replacing the default text with a friendly one in the excerpt instead of showing the login form.

    function excerpt_protected( $content ) {
    	if ( post_password_required() )
    		$content = "Hey, this is a password protected post, the admins of this blog are smart enough to check their loyal fans, so they decided to protect some certain content for the sake of goodness.";
    
    	return $content;
    }

    The above code replaces the default:

    There is no excerpt because this is a protected post.

    …with:

    Hey, this is a password protected post, the admins of this blog are smart enough to check their loyal fans, so they decided to protect some certain content for the sake of goodness.

    Reply
  8. Danny
    Danny July 1, 2009 at 6:38 am |

    I’m sorry Justin, I have misunderstood your post!

    Reply
  9. Samuel Secreto
    Samuel Secreto January 26, 2010 at 11:13 am |

    This is exacly watch I was watching to do in my blog,I was relly neeed of this feature!
    Thanks a lot and congratulations for your excellent blog!

    Reply
  10. Dale
    Dale February 22, 2010 at 6:52 am |

    I don’t suppose anyone knows how to allow the excerpt to show on a protected post? Like a teazer…

    Reply
  11. Modifying Wordpress Password Protected Pages With Teaser
  12. Marty
    Marty August 26, 2011 at 11:32 am |

    Just what I needed, thanks!

    Reply
  13. Alicia
    Alicia September 13, 2011 at 1:34 pm |

    Thanks for sharing Justin.
    This is just what I need!!
    I will try this on my blog. :)

    Reply
  14. cmegown
    cmegown March 5, 2012 at 10:42 pm |

    Is there a better way to do this now with v3.3.1? I tried this, and it ends up spitting out two password forms: one that is generated by the code above, and one that is generated by default. And yes, I am using the_excerpt.

    Thanks, and I hope to hear from you folks soon.

    Reply
  15. Audee
    Audee September 6, 2012 at 8:44 pm |

    I added this codes in function.php and it works perfect. Thanks! :)

    add_filter( 'the_excerpt', 'excerpt_protected' );
    
    function excerpt_protected( $content ) {
    	if ( post_password_required() )
    		$content = get_the_password_form();
    
    	return $content;
    }
    Reply
  16. Cole
    Cole May 17, 2013 at 4:16 am |

    I want to output the password protect form on a single page or post, so that when I enter a specific password into the form, it takes me to any post or page having such password. All I need is just a single page to output my password form irrespective of the post, you can reach any password protected post or page by entering the right password for such post or page. I just hope this is quite explanatory enough.

    Reply

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.