18 Responses

  1. The Frosty @WPCult
    The Frosty @WPCult Published |

    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 Published |

    Nice little trick Justin:)

    Reply
  4. johnbillion
    johnbillion Published |

    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 Published |

    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 Published |

    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 Published |

    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 Published |

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

    Reply
  9. Samuel Secreto
    Samuel Secreto Published |

    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 Published |

    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 Published |

    Just what I needed, thanks!

    Reply
  13. Alicia
    Alicia Published |

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

    Reply
  14. cmegown
    cmegown Published |

    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 Published |

    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 Published |

    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.

css.php