Wishful Coding

Didn't you ever wish your
computer understood you?

Hidden Pages in Wordpress

More often that not, I need to hide pages from the menu and search pages, when setting up a Wordpress blog.

Usually for download and thank-you pages, or other stuff that is only accessible via a direct link.

By default, Wordpress includes a visibility settings, which has 3 values.

  • Public – anyone can see it.
  • Protected – Anyone with the password can see it.
  • Private – Only you can see it

None of them is useful for my goals, however, some digging revealed that a small change would allow you to link directly to password protected pages.

Copy wp-pass.php to unlock.php, and make the changes below.

--- wp-pass.php	2011-09-19 05:17:26.000000000 +0200
+++ unlock.php	2012-01-02 17:38:47.000000000 +0100
@@ -10,8 +10,8 @@
 require( dirname(__FILE__) . '/wp-load.php');
 // 10 days
-setcookie('wp-postpass_' . COOKIEHASH, stripslashes( $_POST['post_password'] ), time() + 864000, COOKIEPATH);
+setcookie('wp-postpass_' . COOKIEHASH, stripslashes( $_GET['post_password'] ), time() + 864000, COOKIEPATH);

Now you can simply link to http://example.com/unlock.php?post_password=foobar&return=/thank-you/

Published on