I’ve searched high and low for an extension which displays a link that deletes this cookie, but nothing turned up. So I simply modified “wp_pass.php” a little and wrote a small function.
First, create a file named “wp_passexpire.php” with the following:
<?php
require( dirname(__FILE__) . ‘/wp-config.php’);// Expire
setcookie(’wp-postpass_’ . COOKIEHASH, ”, time() – 864000, COOKIEPATH);wp_cache_delete($blog_id);
wp_safe_redirect(wp_get_referer());
?>
Second, put the following in “function.php” of your theme:
function pass_expire($before=”", $text=”Delete”, $after=”") {
global $post;
if (!empty($post->post_password)) { // if there’s a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] == $post->post_password) { // and it matches the cookie
echo $before . ‘<a href=”/wp-passexpire.php”>’ . $text . ‘</a>’ . $after;
}
}
}
And lastly, call it with:
<?php pass_expire(’ | ‘, ‘Delete Cookie’, ‘ | ‘); ?>
Test it out, password is “test”.
Related Posts:
- Private entries revisited
- Upgrade Your WordPress
- Question: Threaded Comments
- WordPress: How to Delete Orphaned Comments
- Upgraded to WordPress 2.5














Anja » The downside of doing that is your friends will have to memorize the password. But it works.
I found my solution a few minutes ago. In wp-pass.php, i just set the seconds to “600″, 10 minutes, which works fine for me. I guess it was so simple that no one had bothered to mention it anywhere! But that’s all I needed =)
Anja » That can only be done on the client side unless WP use session cookies.
Hi, can this fix my problem – That public computers will have access to my password-protected posts because of the cookie?
I’d just like the cookie to be deleted when the browser is closed I guess.
Cheers =)
WP was converting single quotes into ticks. Be sure to check for this.
I’m getting the say error when putting that block of code into functions.php
did you figure out what was wrong?
thanks for this work around
George, I don’t see anything wrong with my code… contact me.
Hello Michael,
I have an error in the functions.php with your script:
Parse error: parse error, unexpected T_STRING, expecting ‘,’ or ‘;’ in D:\EasyPHP20\www\wordpress\wp-content\themes\default\functions.php on line xx
Plz help…