Updated Saturday, September 22nd, 2007 at 5:17pm

Show the Intro to Password Protected Posts in WordPress

This is a small hack for WordPress that allows you to show the first part of password protected posts. It will display the content you have before the ‘more’ tag, followed by the standard password box. I wrote this up for a member of the WordPress forum, and I thought I would share it here. Update: Instructions are now provided for WordPress 2.2

Before you begin

The instructions below have been verified in WordPress versions 2.0 through 2.5. The only difference between these versions is the file you have to edit.

Instructions

For WordPress 2.0 or 2.1, open /wp-includes/template-functions-post.php

For WordPress 2.2 or 2.3, open /wp-includes/post-template.php

Find the following text:

$output = get_the_password_form();
return $output;

Replace it with this:

$content = $pages[$page-1];
$content = explode('<!--more-->', $content, 2);
$output = "";
$output .= $content[0];
$output .= get_the_password_form();
return $output;

This next step is optional, but I think it makes it nicer.

In the get_the_password_form function, find the following text (may vary between versions):

This post is password protected.

And replace it with this:

The rest of this post is password protected.

Or whatever text you would like it to show.

  1. This is a much better solutions, without breaking in to core code:

    function change($title)
    {
    $vardi= array(”Å is raksts ir aizsargāts ar paroli. Lai to lasÄ«tu, lÅ«dzu ievadiet paroli:”, “Protected with password”);

    return str_replace($vardi,’LÅ«dzu, ievadiet paroli, lai Å¡o sadaļu apskatÄ«tu!’, $title);
    }

    add_filter(’the_content’,'change’);

    if (have_posts()) : ?>

  2. 12
    mellow

    hi, i’m using wordpress 2.3.2 and I can’t seem to find this:

    $output = get_the_password_form();
    return $output;

    Please advise, thanks!

  3. Notice: The instructions above have been tested with WordPress 2.3, and the same method works. The documentation has been updated to reflect this.

    Michael: Yes, it will work for pages - I just tested it.

  4. Hi there,

    Nice code you got here. Everything above is about having a intro before password in Post.
    I was wondering if the same will work for Pages. I would like to have a intro on my page followed by the password box.

    I am WP 2.2, so hope you can help.

    Thanks

    Michael

  5. you’re amazing!!!! (:

  6. Wesley: Thanks, fixing now.

  7. Everything work except that you reversed the file names.

    For WordPress 2.0, open /wp-includes/template-functions-post.php

    For WordPress 2.2, open /wp-includes/post-template.php

    Again thanks for the hack.

  8. Wesley: I took a look at the files, and the instructions are the same for WordPress 2.2

    The only difference is the file you edit - which is listed above.

  9. 5
    Wesley

    Thanks, I am looking forward to your instruction for the 2.2

  10. Wesley: Since the template-functions-post.php file does not even exist in WP 2.1, no. I plan to eventually post updated instructions for 2.1 though.

  11. Is this mod work with the current release WP 2.2.1?

    thanks

    Wesley

  12. jalansutera: Unfortunately not. I have not done much work with modifications to the feed generation system yet.

  13. Hi.. I like your hack. I have put it on my blog too.

    However, the feed of the protected entry shows ” There is no excerpt because this is a protected post”. Do you know how to make the excerpt of the post appears? Do you know how to do it?

    Please help…

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.