Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här lösenordskyddar du en page eller ett post i WordPress

Har du någonsin funderat på att skapa ett blogginlägg bara för nära vänner eller familjemedlemmar? Eller publicera ett post bara för editors på din WordPress site? Som publiceringsplattform för innehåll har WordPress några grundläggande alternativ för innehållssynlighet som de flesta nybörjare förbiser. I den här artikeln visar vi dig hur du skapar en password-skyddad page eller post i WordPress.

När du skriver posts finns det ett alternativ som heter Synlighet, som är inställt på Offentlig som standard. Om du klickar på Edit kommer du att se alternativ som Password Protected och Private.

Making posts Private or Password Protected in WordPress

Klicka bara på Password Protected för att lägga till ett password till din post. Om du gör det kommer endast de vänner, familjemedlemmar eller användare som du delar detta lösenord med att kunna se detta post.

Ett privat post i WordPress är endast synligt för inloggade användare med användarrollen Editor eller Administrator i WordPress.

Samma trick fungerar även för att skydda en page i WordPress med ett password.

Dölja password-skyddade posts helt från homepage och archives

Alla dina lösenordskyddade inlägg kan visas bland resten av dina posts på homepage eller archives på din site. Om du vill dölja dem helt, använd då den här koden i ditt temas functions.php eller i ett site-specifikt plugin.


// Hide protected posts

function exclude_protected($where) {
	global $wpdb;
	return $where .= " AND {$wpdb->posts}.post_password = '' ";
}

// Where to display protected posts
function exclude_protected_action($query) {
	if( !is_single() && !is_page() && !is_admin() ) {
		add_filter( 'posts_where', 'exclude_protected' );
	}
}

// Action to queue the filter at the right time
add_action('pre_get_posts', 'exclude_protected_action');

Det är all. Dina skyddade posts kommer ej att visas på webbplatsens homepage eller archives. Du kan skicka postens URL till användare med passwordet.

Vi hoppas att den här artikeln hjälpte dig att skydda poster med lösenord i WordPress. Du kanske också vill kontrollera hur du gör en hel site i WordPress lösen ordsskyddad utan registrering av användare.

Om du gillade den här artikeln, vänligen prenumerera på vår YouTube-kanal för WordPress video tutorials. Du kan också hitta oss på Twitter och Google+.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

31 kommentarerLeave a Reply

  1. Once enter the password in on the password-protected page and it displays the protected information, how can I log out again to see what the page looks like to non-logged-in visitors?
    Thank you

  2. I have set the Blog page to password protected. The site is juliananoreen.com.
    Saved.
    It still is visible! Had a friend test from a cell phone. Visible there too.
    Is there an additional setting that I am overlooking?
    I am expecting to see a message and password section but the test posts are completely visible.
    Thanks for your insights!
    N

  3. I have password protected a pages (and children pages…not posts). I want it to prompt the user to reinsert the password when they leave the page…
    I saw that you can set the post_password_expires to 0 but where would I do it for a page?

  4. My password protection is not working. It keeps referring back to the password prompt. Yes i have the correct password. Any ideas?

  5. I made sometime ago a Password protected post, but I can’t remember the password.

    Can you help me with this ?

    thanks in advance

  6. Is there a way to change the default text to these password protected pages? I would like to leave a link in this text if it’s possible?

    Thanks,
    J

  7. Hi, I use password protection for a specific page. However, whenever I use the password to access the page, a pop-up window appears and wants my admin credentials. How can I make this issue disappear. That shouldn’t happen. I used passwort protection before and it worked fine, but now it doesn’t anymore.

  8. I have pages not posts that are password protected. Being pages i have no issue with them showing up in archives etc. I have them on my menu. I want only the main page not any of its children to show up in my custom menu until the user logs in. Is that possible?

  9. the default WP expiry of the login is 10 days!! That is not much use on a private computer. I found if I used this plugin ‘Protected Posts Logout Button’ and added the logout button to every page with the password it logged out of all of them when I clicked one. It also allows setting auto logout time/cookie expiry. So I set 30 minutes in case a user does not logout.

  10. Static page – I set visibility to “password” and set a password. Worked a treat for a few weeks. In the last couple of days when entering password page results to “Forbidden”. Password is correct. have disabled Plugins, activated default themes and still same result – cannot access password protected content.

    Any thoughts…

    Is this a server host issue or WP issue?

  11. I tried this and find the following error: when someone wants to use it, they fill in the password (on a page) and they are redirected to the captcha and directed to my wordpress login in. That should not be the case? I do not understand this.

  12. Hi, interesting – I’ve never seen this before (I don’t think!). …Will this be bad for SEO purposes? Can search engines still crunch the content?

  13. So this was pretty cool – it protects the page. I enter the correct password, and the page shows up fine. Now, when I Refresh the page, it still shows up. When does the password prompt come up again?

  14. I am unable to access the private blog from my iphone as it only allows me to type the password in capital letters, yet my password is all lowercase.
    Also any text entry like subscribe box is all in caps too.

    how can I resolve this apart from changing the password to all caps.

    thanks
    Justin

  15. I think it’s a great feature. How can I open the password protected Page with a Query String? So I can send a Link to my friends. Thanks for any ideas.

    Thomas

  16. Hello sir,
    i added a link in my site and i want that whenever anybody click on in there then by Clicking this link will bring up a password prompt, if user successfully enters password they are allowed to access a password-protected page.

    Thanks in advance

  17. This works great EXCEPT the post is still showing up in the “Latest Posts” widget. Any code change to fix that?

  18. is there any way to make it available to logged in users. By default even a logged in admin cannot see this password protected post.

    Is there any way we can make it available to all logged in users?

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.