12 responses to “Showing the post password form for excerpts in WordPress”

  1. The Frosty @WPCult

    That’s really awesome. Short and sweet!

  2. Show the post password form for the_excerpt in a WordPress — WPCult

    [...] Show the password on post excerptsBy Austin on June 24, 2009 Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Justin Tadlock has written a nice tutorial on how to show a password form field instead of the defau… [...]

  3. Adam W. Warner

    Nice little trick Justin:)

  4. johnbillion

    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?

  5. J Mehmett

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

  6. Danny

    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!

  7. J Mehmett

    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.

  8. Danny

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

  9. Samuel Secreto

    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!

  10. Dale

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

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 (e.g., 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.