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

Parola Korumalı Yazılar WordPress Döngüsünden Nasıl Gizlenir

WordPress şifre korumalı yazılar oluşturmanıza olanak tanır. Geçenlerde okuyucularımızdan biri parola korumalı yazıları siteden gizlemenin mümkün olup olmadığını sordu. Varsayılan olarak, WordPress parola korumalı bir yazının içeriğini gizler, ancak yazı başlığını ‘Korumalı’ ön ekiyle göstermeye devam eder. Bu makalede, parola korumalı yazıları WordPress döngüsünden nasıl gizleyeceğinizi göstereceğiz.

WordPress’te Parola Korumalı Yazıları Neden Gizleyelim?

Varsayılan olarak, WordPress parola korumalı gönderiyi başlığı ve ‘korumalı’ önekiyle görüntüler. Kullanıcıların yazının içeriğini görüntülemek için şifreyi girmeleri gerekecektir.

Password protected posts displayed on homepage and in widgets

Bu gönderi başlığı ana sayfada, arşivlerde, son gönderiler widget’ında vb. görünür. Bazı içerikleri tamamen gizli tutmak istiyorsanız, bu ideal değildir.

Şifresi olmayan kullanıcılar yalnızca gönderi başlığını görmekle kalmaz, aynı zamanda şifre girmeyi de deneyebilirler. Hepimizin bildiği gibi, şifreler kırılabilir.

Bunu söyledikten sonra, parola korumalı gönderilerinizi WordPress döngüsünden nasıl gizleyeceğinize bir göz atalım, böylece diğer kullanıcılar bunları göremez.

WordPress’te Parola Korumalı Yazıları Gizleme

Bu kodu temanızın functions.php dosyasına veya siteye özel bir eklentiye eklemeniz yeterlidir.

function wpb_password_post_filter( $where = '' ) {
    if (!is_single() && !is_admin()) {
        $where .= " AND post_password = ''";
    }
    return $where;
}
add_filter( 'posts_where', 'wpb_password_post_filter' );

Bu kod basitçe posts_where filtresini kullanarak WordPress’e gönderilen sorguyu değiştirir. WordPress’ten parolası olmayan tüm gönderileri getirmesini ister.

Web sitenizi ziyaret ettiğinizde, parola korumalı gönderilerin artık ana sayfada, arşivlerde veya son gönderiler gibi widget’larda görünmediğini göreceksiniz.

Before and after hiding protected posts in WordPress

Gönderinin kendisine doğrudan bir URL aracılığıyla erişerek gönderiyi ziyaret etmeye devam edebilirsiniz.

Yukarıdaki örnek, parola korumalı gönderileri tüm kullanıcılardan gizler. Peki ya çok yazarlı bir WordPress sitesi işletiyorsanız ve korumalı gönderilerin özel gönderileri düzenleme yeteneğine sahip kullanıcılar tarafından görüntülenebilmesini istiyorsanız?

Yukarıdaki kodu aşağıdaki gibi başka bir koşul etiketi ile değiştirmeniz yeterlidir:

function wpb_password_post_filter( $where = '' ) {
   if (!is_single() && !current_user_can('edit_private_posts') && !is_admin()) {
        $where .= " AND post_password = ''";
    }
    return $where;
}
add_filter( 'posts_where', 'wpb_password_post_filter' );

Bu örnekte, bir kullanıcının parola korumalı gönderileri düzenleyemeyeceğini kontrol ediyoruz, ardından yalnızca parolası olmayan gönderileri gösteriyoruz. Böylece yönetici ve editör kullanıcı rollerine sahip tüm kullanıcılar sitenizin ön ucunda parola korumalı gönderileri görecektir.

Umarız bu makale sitenizdeki WordPress döngüsünden parola korumalı gönderileri gizlemenize yardımcı olmuştur. WordPress’te özel ve korumalı gönderilerin önekini değiştirme hakkındaki eğitimimizi de görmek isteyebilirsiniz.

Bu makaleyi beğendiyseniz, WordPress video eğitimleri için lütfen YouTube Kanalımıza abone olun. Bizi Twitter ve Google+‘da da bulabilirsiniz.

Açıklama: İçeriğimiz okuyucu desteklidir. Bu, bazı bağlantılarımıza tıklarsanız komisyon kazanabileceğimiz anlamına gelir. WPBeginner'ın nasıl finanse edildiğini, neden önemli olduğunu ve nasıl destek olabileceğinizi görün. İşte editoryal sürecimiz.

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.

Ultimate WordPress Araç Kiti

Araç setimize ÜCRETSİZ erişim sağlayın - her profesyonelin sahip olması gereken WordPress ile ilgili ürün ve kaynaklardan oluşan bir koleksiyon!

Reader Interactions

14 yorumBir Cevap Bırakın

  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. David Brown says

    Thank you for explaining how to *really* do it in code; I wasn’t expecting that from a site called “wpbeginner.com”! (Still works in 2024 and WP 6.5.2, by the way.)

    So many sites pretend to offer solutions but really want you to use their plug-in that overcomplicates some simple thing and leaves your site exposed to any vulnerabilities they might introduce and never patch.

    • WPBeginner Support says

      It would depend on the site and plugin as plugins can be for simply adding the same code as code from an article without needing to know how to edit files which is why sites recommend them. Glad you found our site and guide helpful :)

      Yönetici

  3. Vincent Zhang says

    Thank you guys so much. This really helped me. I appreciate it. Please keep more of this type of posts coming that do not involve using a plugin.

  4. Mark says

    I created a site specific plugin and followed these steps and it worked for hiding my post on the “Posts” page of my site. However, the post is still visible on a Related Posts widget for each individual post. (Very similar to the image you have above, however my Password protected post is still visible.)

    Is there anything I can do to fix this?

  5. Alex says

    I wanted to make my own code adjustment to show the posts if you could read_private_posts.

    function remove_password_protected_posts( $where = ” ) {
    if (!is_single() && !current_user_can(‘read_private_posts’) && !is_admin() ) {
    $where .= ” AND post_password = ””;
    }
    return $where;
    }
    add_filter( ‘posts_where’, ‘remove_password_protected_posts’ );

    Great post as usual. Thanks.

  6. Harin says

    Hi guys

    I made a site specific plugin with the following code:

    If I try to attach a nextgen gallery to my post, the gallery doesn’t load, as soon as I disable the plugin, the nextgen gallery goes back to normal.

    Regards

  7. Brandon says

    Thanks for this snippet. So helpful!

    Regarding hiding these posts from the rss feed, I ran across this snippet.


    function rss_filter_protected($query) {
    if ($query->is_feed) {
    add_filter('posts_where', 'rss_filter_password_where');
    }
    return $query;
    }
    add_filter('pre_get_posts','rss_filter_protected');

  8. Chris says

    Thanks for that great tip!
    But are these posts hidden from the loop with your code snippet also hidden from the RSS feed?

Bir Cevap Bırakın

Yorum bırakmayı seçtiğiniz için teşekkür ederiz. Lütfen tüm yorumların yorum poli̇ti̇kasi uyarınca denetlendiğini ve e-posta adresinizin yayımlanmayacağını unutmayın. Ad alanında anahtar kelime KULLANMAYIN. Kişisel ve anlamlı bir sohbet edelim.