親しい友人や家族のためだけにブログ投稿をしようとフィードバックしたことはありますか?あるいは、WordPressサイトでエディターのためだけの投稿を公開したことがありますか?コンテンツ公開プラットフォームであるWordPressには、ほとんどの初心者が見落としている基本的なコンテンツ可視化オプションが用意されています。この投稿では、WordPressでパスワードで保護されたページや投稿を作成する方法を紹介します。
投稿を書くとき、Visibilityというオプションがあり、初期設定ではPublicに設定されています。編集]をクリックすると、[パスワードで保護]や[非公開]などのオプションが表示されます。
投稿にパスワードを追加するには、パスワード保護をクリックします。そうすることで、このパスワードを共有する友人、家族、ユーザーだけがこの投稿を見ることができるようになります。
WordPressの非公開投稿は、WordPressのエディターまたは管理者レベルのユーザー権限でログイン中のユーザーにのみ表示されます。
WordPressでページをパスワードで保護する場合も、同じトリックが使えます。
パスワードで保護された投稿をホームページやアーカイブから完全に非表示にする
パスワードで保護された投稿はすべて、サイトのホームページやアーカイブに他の投稿と混ざって表示されることがあります。それらを完全に非表示にしたい場合は、テーマのfunctions.phpまたはサイト固有のプラグインでこのコードを使用してください。
// 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');
これですべてです。保護された投稿はサイトのトップページやアーカイブには表示されません。パスワードを使って投稿のURLをユーザーに送ることができます。
この投稿がWordPressで投稿をパスワードで保護するのにお役に立てば幸いです。ユーザー登録なしでWordPressサイト全体をパスワードで保護する方法もご覧ください。
この投稿が気に入った場合は、WordPressの動画チュートリアルをYouTubeチャンネルに登録してください。Twitterや Google+でもご覧いただけます。
MJ
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
WPBeginner Support
The simplest method would be to use an incognito/private browser window
管理者
Noreen
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
WPBeginner Support
Hi Noreen,
The blog page is a place holder to display your WordPress blog posts. Unlike regular WordPress pages which show page content, this page shows your blog posts list. Normally, the WordPress password protect feature works on the content of a post or page. However, a blog page has no content of its own. This is why before the password protection can kick in, the blog posts get displayed.
管理者
Noreen
Oh, darn!
Have any ideas how to fully lock it down so I can add content and all elements are hidden? I did initially try password protecting the posts – not an option b/c the title and feature images are still visible. Hmmmmm….?
TY!
WPBeginner Support
For what it sounds like you’re wanting, you would want to set up a membership plugin to password your content: https://www.wpbeginner.com/plugins/5-best-wordpress-membership-plugins-compared/
Mary Ann
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?
Ben
My password protection is not working. It keeps referring back to the password prompt. Yes i have the correct password. Any ideas?
ellen
I made sometime ago a Password protected post, but I can’t remember the password.
Can you help me with this ?
thanks in advance
ellen
I just found it…!!!
Diao
If I dont know the password, how to read a protected post?
Justin
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
Stephanie
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.
Mark
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?
WPBeginner Support
See our guide on how to show different menus to logged in users in WordPress
管理者
Mark
Does that code work where it is not technically a “user” it is entering the password for a protected page? Anyone can do that, they do not need to be registered as a user.
Mark Gason
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.
Ian
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?
Amanda
I’m having the same issue.
Naomi
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.
tom
this was working great until a recent update now I just get a 404 page..
WPBeginner Support
Try updating your permalinks. Simply go to Settings > Permalinks and click on the save changes button.
管理者
Tom
Yes, first thing I did, was surprised when that didn’t fix it.
WPBeginner Support
We tested the code again with the latest version. It worked fine on our end. Have you tried troubleshooting steps like deactivating all plugins, switching to default theme, deleting and regenerating .htaccess file?
Sean Vandenberg
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?
Maryam
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?
Justin
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
Thomas Stahl
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
Zeeshan
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
Ryan
This works great EXCEPT the post is still showing up in the “Latest Posts” widget. Any code change to fix that?
mdfaizan
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?