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

WordPress’te Öne Çıkan Görselleri Yazılardan Toplu Olarak Kaldırma

Geçenlerde bir okuyucumuz bize WordPress’te öne çıkan görselleri yazılardan nasıl toplu olarak kaldırabileceklerini sordu. WPBeginner’da öne çıkan görselleri (yazı küçük resimleri) birçok kez tartıştık. WordPress‘te öne çıkan görsellerin nasıl ekleneceğini, WordPress’te yeni görsel boyutlarının nasıl ekleneceğini, küçük resimlerin nasıl yeniden oluşturulacağını ve hatta WordPress’te bir yazıya birden fazla öne çıkan görselin nasıl ekleneceğini gösterdik. Bu makalede, WordPress’te öne çıkan görselleri yazılardan nasıl toplu olarak kaldıracağınızı göstereceğiz.

Gönderi Küçük Resimlerinin veya Öne Çıkarılan Görsellerin Toplu Olarak Kaldırılmasıyla İlgili Sorun

Ne yazık ki, varsayılan olarak öne çıkan görselleri yalnızca her bir gönderiyi düzenleyerek ve öne çıkan görseli kaldırarak kaldırabilirsiniz. Eğer bir kullanıcının öne çıkan görseller içeren yüzlerce gönderisi varsa, bunları tek tek kaldırmak çok zaman alıcı bir iş olabilir. Bunun yerine, farklı bir yaklaşım deneyeceğiz. Bir veritabanı sorgusu çalıştıracağız ve tüm gönderilerdeki öne çıkan görsellerin ayarını kaldıracağız.

Devam etmeden önce, aşağıdaki kodun WordPress sitenizdeki tüm yazılardan öne çıkan görselleri sadece yapıştırarak kaldıracağını lütfen unutmayın. Ayrıca, bu kodun yüklediğiniz hiçbir görseli silmeyeceğini, Medya Kitaplığı’nda hala mevcut olacaklarını ve istediğiniz zaman yeniden kullanabileceğinizi unutmayın.

Tek yapmanız gereken bu kodu kopyalayıp temanızın functions.php dosyasına yapıştırmak.


global $wpdb;
$wpdb->query( "
    DELETE FROM $wpdb->postmeta 
    WHERE meta_key = '_thumbnail_id'
" );

Hepsi bu kadar. functions.php dosyanızı kaydettiğiniz anda bu betik bir veritabanı sorgusu çalıştıracak ve tüm gönderilerden öne çıkan resimleri kaldıracaktır.

Önemli: Lütfen functions.php dosyanızı kaydettikten hemen sonra bu kodu kaldırın. Bu kod yazılardan öne çıkan resimleri kaldırmaya devam edeceğinden WordPress’te öne çıkan resimleri ayarlayamazsınız.

Umarız bu makale biraz zaman kazanmanıza ve WordPress yazılarından öne çıkan görselleri toplu olarak kaldırmanıza yardımcı olmuştur. Sorularınız ve geri bildirimleriniz için lütfen aşağıya bir yorum bırakın.

Kaynak: Kaiser

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

42 yorumBir Cevap Bırakın

  1. Syed Balkhi

    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. Gregh777

    This little line of code saved me a lot of hassle. Thanks for that! I had imported about 50 articles and WordPress was saying each one had a featured image when it did not have one.

    I already know why it was doing that…long story…however, how am I to remove the featured image when there is nothing to remove?? Just paste these lines of code into the functions.php file like the article says and voila! All ghost images removed :D

    wpbeginner makes me SO happy ;)

    • WPBeginner Support

      Glad our article could help :)

      Yönetici

  3. Asfianda

    Thanks, this so helpfull for me.

    • WPBeginner Support

      You’re welcome, glad our content could be helpful :)

      Yönetici

  4. hercules

    Deleting all the server images assigned to the thumbnails is relatively simple, now, how to condition to delete all uploads not used by the server as featured images? This should be the most interesting, clean the images not used by the system, in order to polish the machine resources deleting junk images, not used.

  5. Peter

    Yes! So helpful, thank you!!!

  6. aman

    it works thank you , but what if i want to remove the post that don’t have feature image , how can i do that ?

  7. Imbert

    Thanks a lot, you really rocks guys!!!

  8. lszllvnt

    it works ! just don’t use with child theme.

  9. Em

    Followed the instructions to the letter. Got this error message: Parse error: syntax error, unexpected ‘$wpdb’ (T_VARIABLE) in /home/ruznnjep/public_html/wp-content/themes/natalie/functions.php on line 411

    Blog broken. Had to reinstall. Thanks.

  10. Dan

    Thank you! It is an excellent advice to remove all featured images

  11. Jax

    Is there anyway to undo this? I didnt realise it would remove thumbnail images as well. I have tried restoring the thumbnails but it is not working. Thanks

  12. Mike

    #1. Are we 100% positive that the current code does NOT delete any images from my media folder? And simply “unset” them from featured image?

    #2. You mention “However, the query can be modify to exclude certain post types.” Can you share the code I would use to avoid a category with ID=25?

    Thank you so much,
    Mike

  13. RaviTeja Adibhatla

    Works like charm. Thanks man :)

  14. Afzal

    Thanks Buddy… this is what i need … Thanks A lot for this helping tutorials..
    Love you bro

  15. srijita chattopadhyay

    THANK YOU!

  16. Raakib Hasan

    This code remove the post thumbnails as well. But I want to keep the post thumbnail ( when it show grids on Homepage) and just want to remove the feature image from inside the posts. Is this possible?

  17. Luke Melbourne

    Awesome! Just what I needed. Thank you.

  18. Karen

    Thank you so much for this tutorial! It worked perfectly!

  19. Zaid Sparrow

    Hi, will I have my all featured images back on place after removing this code? or I’ll have to set them manually again?

  20. Abdul

    this is exactly what i was looking for but i have tried these and it’s not working for me.i am using generate child theme and on my home page some posts are still showing featured image.i also turned them off in genesis settings but nothing happened.how do i stop featured images to be shown on blog page?Thanks

  21. w0ngsimp4ng

    thanks its work :). I Have removed all featured image and rebuild again with auto post thumbnail plugin.

  22. Jeff

    Hi,
    I pasted the above code into my site with no luck. Is this thread still accurate and active?

    thanks,
    Jeff

  23. Marcelo

    After delete my related images my images from homepage desappeared, but when I go to post details it appears normally. Before run the script, the homepage used the images from inside the post and not from related images, so I really don’t know why they desappeared from my homepage. Do you have any idea why this happened?

  24. Robin Solanki

    Thanks a lot, you helped me saved a lot of time.

  25. Rahul

    Is there a plugin or codes to remove both post and images attached to a post when we delete it? I mean if i delete a post i also want to delete images related to that post also.

      • Rahul

        Wish someone would have made a plugin like that because deleting images from 100-200 posts is very time consuming… ?? if any plugin of that kind comes up pls do update it in ur site.. thanks for your reply

  26. Nicholas

    Is it possible to query a specific category and remove just those categories posts featured images?

  27. Justin Edwards

    BEWARE

    I used this code yesterday to try to delete the featured images as part of an upgrade to a new WordPress theme. While it did delete the featured images from posts, it also deleted them from the media library and I think it’s also deleted the original files from the server.

    Having used this code to try and speed thing up, I now find myself having to re-install and re-link over 2,500 images for my site.

    • WPBeginner Support

      Justin, we tested the code again. It does not delete files from your media library or your server. It just unsets featured images.

      Yönetici

      • Sudip

        I am facing the same problem. After adding this code, few images are being erased from media library.

        • WPBeginner Support

          Sudip, thank you for notifying us. We have updated the article. Please try the new code instead.

  28. UaMV

    One should also note that this deletes featured images not just from standard post, but from all posts (including custom post types), correct?

  29. James DiGioia

    Wouldn’t it be easier to just run a query on DB directly?

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.