× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Require Wordpress private page/post password always

Nicolas Fernandez
Dec 19, 2015
<p>You can prompt for the private posts/pages/articles... password each time by adding this to your current theme functions.php</p> <pre><code class="language-php">/** * Always expire Post Password Session cookie */ add_action( 'wp', 'post_pw_sess_expire' ); function post_pw_sess_expire() { if ( isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) setcookie('wp-postpass_' . COOKIEHASH, '', 0, COOKIEPATH); }</code></pre> <p>Basically this snippet asks if there's a post password cookie set in the user browser, if there is one we expire it using setcookie('wp-postpass_' . COOKIEHASH, '', 0, COOKIEPATH); (notice we clear the password on the 2nd argument, and expire the cookie by setting the lifetime to 0)</p>
comments powered by Disqus