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

Comment protéger par mot de passe une page ou une publication dans WordPress

Note éditoriale : Nous percevons une commission sur les liens des partenaires sur WPBeginner. Les commissions n'affectent pas les opinions ou les évaluations de nos rédacteurs. En savoir plus sur Processus éditorial.

Avez-vous déjà pensé à créer une publication de blog uniquement pour vos amis proches ou les membres de votre famille ? Ou de publier un article réservé aux éditeurs/éditrices sur votre site WordPress ? En tant que plateforme de publication de contenu, WordPress est livré avec quelques options de base de visibilité du contenu que la plupart des débutants négligent. Dans cet article, nous allons vous afficher comment créer une page ou une publication protégée par mot passe dans WordPress.

Lors de la rédaction des publications, il y a une option appelée Visibilité, qui est définie sur Public par défaut. Si vous cliquez sur Modifier, alors vous verrez des options telles que Protégé par mot de passe et Privé.

Making posts Private or Password Protected in WordPress

Il vous suffit de cliquer sur Protégé par mot de passe pour ajouter un mot de passe à votre publication. Ainsi, seuls les amis, les membres de la famille ou les utilisateurs/utilisatrices avec lesquels vous partagez ce mot passe pourront voir cette publication.

Une publication privée dans WordPress est visible uniquement par les utilisateurs/utilisatrices connectés ayant le rôle d’ éditeur/éditrices ou d’administrateur/administratrice dans WordPress.

La même astuce fonctionne pour la protection par mot de passe d’une page dans WordPress.

Masquer complètement les publications protégées par un mot de passe sur la page d’accueil et dans les archives

Tous vos messages protégés par mot de passe peuvent apparaître parmi les autres publications sur la page d’accueil ou dans les archives de votre site. Si vous souhaitez les masquer complètement, utilisez ce code dans le fichier functions.php de votre thème ou dans une extension spécifique à votre site.


// 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');

C’est tout. Vos publications protégées n’apparaîtront pas dans la page d’accueil ou dans les archives du site. Vous pouvez envoyer l’URL de la publication aux utilisateurs/utilisatrices avec le mot de passe.

Nous espérons que cet article vous a aidé à protéger vos publications par mot de passe sur WordPress. Vous pouvez également consulter la rubrique Comment protéger tout un site WordPress par mot de passe sans inscription des utilisateurs/utilisatrices.

Si vous avez aimé cet article, veuillez vous abonner à notre chaîne YouTube pour des tutoriels vidéo sur WordPress. Vous pouvez également nous trouver sur Twitter et Google+.

Divulgation : Notre contenu est soutenu par les lecteurs. Cela signifie que si vous cliquez sur certains de nos liens, nous pouvons gagner une commission. Consultez comment WPBeginner est financé, pourquoi cela compte et comment vous pouvez nous soutenir. Voici notre processus éditorial.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

L'ultime WordPress Toolkit

Accédez GRATUITEMENT à notre boîte à outils - une collection de produits et de ressources liés à WordPress que tous les professionnels devraient avoir !

Reader Interactions

32 commentairesLaisser une réponse

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. MJ says

    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

  3. Noreen says

    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 says

      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.

      Administrateur

  4. Mary Ann says

    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?

  5. Ben says

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

  6. ellen says

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

    Can you help me with this ?

    thanks in advance

  7. Justin says

    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

  8. Stephanie says

    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.

  9. Mark says

    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?

  10. Mark Gason says

    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.

  11. Ian says

    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?

  12. Naomi says

    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.

  13. Sean Vandenberg says

    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?

  14. Maryam says

    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?

  15. Justin says

    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

  16. Thomas Stahl says

    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

  17. Zeeshan says

    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

  18. mdfaizan says

    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?

Laisser une réponse

Merci d'avoir choisi de laisser un commentaire. Veuillez garder à l'esprit que tous les commentaires sont modérés selon notre politique de commentaires, et votre adresse e-mail ne sera PAS publiée. Veuillez NE PAS utiliser de mots-clés dans le champ du nom. Ayons une conversation personnelle et significative.