Adding a link to logout of password protected posts in WordPress

I needed to add a “logout” link to a theme on which I’m working that would clear the cookie WordPress sets for password protected posts. This is what I came up with:

<?php if ( $_COOKIE['wp-postpass_' . COOKIEHASH] ) { ?>
  | <a href="<?php echo get_template_directory_uri(); ?>/includes/logout.php">Log Out</a>
<?php } ?>

COOKIEHASH is a constant set by WordPress that contains a hash of your blog URL.

For the actual cookie clearing functionality, you can use something like this script over at Stack Overflow.