{"id":40541,"date":"2014-05-02T20:32:43","date_gmt":"2014-05-02T15:02:43","guid":{"rendered":"https:\/\/www.quickonlinetips.com\/archives\/?p=40541"},"modified":"2026-10-13T13:42:49","modified_gmt":"2026-10-13T08:12:49","slug":"add-logout-button-to-password-protected-wordpress-posts","status":"publish","type":"post","link":"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/","title":{"rendered":"How to Add a Logout Button to Password Protected Posts in WordPress (2026)"},"content":{"rendered":"<p>WordPress password-protected posts have a hidden problem: there&#8217;s no logout. Once a visitor enters the password, a cookie keeps the post unlocked (for 10 days by default), so anyone using that browser later can read it. In 2014 we added a <strong>logout button to password protected posts<\/strong> on QuickOnlineTips with a small plugin. That plugin hasn&#8217;t been updated in years, so here&#8217;s a simple, current way to do it in 2026.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-64462\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/password-protected-posts-logout-1024x538.webp\" alt=\"Logout button for password protected WordPress posts\" width=\"1024\" height=\"538\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/password-protected-posts-logout-1024x538.webp 1024w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/password-protected-posts-logout-300x158.webp 300w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/password-protected-posts-logout-150x79.webp 150w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/password-protected-posts-logout-768x403.webp 768w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/password-protected-posts-logout.webp 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p><strong>Quick answer:<\/strong> WordPress stores the post password in a cookie named <code>wp-postpass_<\/code> plus a hash. To log visitors out, add a small code snippet that shows a &#8220;Log out&#8221; link on unlocked protected posts and deletes that cookie when clicked. Add it with a code snippets plugin or your child theme&#8217;s functions.php, and optionally shorten how long the password cookie lasts.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_90 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6afe300cd39cc\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #1a202c;color:#1a202c\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #1a202c;color:#1a202c\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6afe300cd39cc\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Why_password_protected_posts_need_a_logout\" >Why password protected posts need a logout<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Add_a_logout_link_with_a_code_snippet\" >Add a logout link with a code snippet<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Style_the_logout_button\" >Style the logout button<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Shorten_the_password_cookie\" >Shorten the password cookie<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Plugin_option\" >Plugin option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Better_options_for_private_content\" >Better options for private content<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#FAQ\" >FAQ<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#How_long_does_a_WordPress_post_password_last\" >How long does a WordPress post password last?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Does_logging_out_of_WordPress_clear_post_passwords\" >Does logging out of WordPress clear post passwords?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/05\/add-logout-button-to-password-protected-wordpress-posts\/#Are_password-protected_posts_secure\" >Are password-protected posts secure?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Why_password_protected_posts_need_a_logout\"><\/span>Why password protected posts need a logout<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>The unlock cookie survives closing the browser.<\/li>\n<li>On shared or family computers, the next person can open the post without the password.<\/li>\n<li>If you change the post password, existing cookies stop working, but that locks everyone out.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Add_a_logout_link_with_a_code_snippet\"><\/span>Add a logout link with a code snippet<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Paste this into the free Code Snippets plugin or your child theme&#8217;s <code>functions.php<\/code>:<\/p>\n<pre><code>\/\/ Clear the post password cookie when ?postpass_logout=1 is visited\nadd_action( 'init', function () {\n    if ( isset( $_GET['postpass_logout'] ) ) {\n        setcookie( 'wp-postpass_' . COOKIEHASH, '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN );\n        wp_safe_redirect( remove_query_arg( 'postpass_logout' ) );\n        exit;\n    }\n} );\n\n\/\/ Show a logout link on unlocked password-protected posts\nadd_filter( 'the_content', function ( $content ) {\n    if ( is_singular() &amp;&amp; post_password_required() === false &amp;&amp; ! empty( get_post()-&gt;post_password ) ) {\n        $url = esc_url( add_query_arg( 'postpass_logout', '1' ) );\n        $content .= '&lt;p&gt;&lt;a class=\"btn-logout\" href=\"' . $url . '\"&gt;Log out of this protected post&lt;\/a&gt;&lt;\/p&gt;';\n    }\n    return $content;\n} );<\/code><\/pre>\n<p>Test it on a staging site first, then open a protected post, enter the password and click the link: the password form should reappear.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Style_the_logout_button\"><\/span>Style the logout button<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We used a large green button floating to the right. A modern version:<\/p>\n<pre><code>.btn-logout {\n  display: inline-block;\n  padding: 10px 18px;\n  background: #1a7f37;\n  color: #fff;\n  font-weight: 700;\n  border-radius: 8px;\n  text-decoration: none;\n}<\/code><\/pre>\n<p>If changes don&#8217;t appear, clear your cache or <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2011\/12\/force-browser-css-refresh\/\">force a CSS refresh<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Shorten_the_password_cookie\"><\/span>Shorten the password cookie<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>WordPress keeps the cookie for 10 days. To make it expire when the browser closes, add:<\/p>\n<pre><code>add_filter( 'post_password_expires', '__return_zero' );<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Plugin_option\"><\/span>Plugin option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <a href=\"https:\/\/wordpress.org\/plugins\/protected-posts-logout-button\/\" target=\"_blank\" rel=\"noopener\">Protected Posts Logout Button<\/a> plugin we used in 2014 still adds a button automatically, but it hasn&#8217;t been tested with recent WordPress versions, so the snippet above is safer.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Better_options_for_private_content\"><\/span>Better options for private content<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Post passwords are shared secrets, not real security. For members-only content, use user accounts and a membership plugin; see our guide to <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2010\/06\/wordpress-blog-to-membership-site\/\">turning a WordPress blog into a membership site<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"FAQ\"><\/span>FAQ<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_long_does_a_WordPress_post_password_last\"><\/span>How long does a WordPress post password last?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The unlock cookie lasts 10 days by default, unless you change it with the post_password_expires filter.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_logging_out_of_WordPress_clear_post_passwords\"><\/span>Does logging out of WordPress clear post passwords?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No. The post password cookie is separate from your login.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Are_password-protected_posts_secure\"><\/span>Are password-protected posts secure?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>They keep casual visitors out, but anyone with the password can share it. Use member accounts for sensitive content.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress password-protected posts have a hidden problem: there&#8217;s no logout. Once a visitor enters the password, a cookie keeps the&#8230;<\/p>\n","protected":false},"author":4,"featured_media":64462,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6,7],"tags":[17],"class_list":["post-40541","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogging","category-security","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/40541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/comments?post=40541"}],"version-history":[{"count":3,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/40541\/revisions"}],"predecessor-version":[{"id":65508,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/40541\/revisions\/65508"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media\/64462"}],"wp:attachment":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media?parent=40541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/categories?post=40541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/tags?post=40541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}