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

Wie man Featured Images in WordPress massenhaft aus Posts entfernt

Hinweis der Redaktion: Wir erhalten eine Provision für Partnerlinks auf WPBeginner. Die Provisionen haben keinen Einfluss auf die Meinung oder Bewertung unserer Redakteure. Erfahre mehr über Redaktioneller Prozess.

Kürzlich hat uns einer unserer Leser gefragt, wie man in WordPress Bilder von Beiträgen entfernen kann? Auf WPBeginner haben wir schon viele Male über Featured Images (Post-Thumbnails) gesprochen. Wir haben Ihnen gezeigt, wie man in WordPress Bilder hinzufügt, wie man neue Bildgrößen in WordPress hinzufügt, wie man Thumbnails neu generiert und wir haben Ihnen sogar gezeigt, wie man mehrere Bilder zu einem Beitrag in WordPress hinzufügt. In diesem Artikel zeigen wir Ihnen, wie Sie in WordPress Bilder aus Beiträgen entfernen können.

Das Problem bei der Massenentfernung von Post-Thumbnails oder Featured Images

Leider können Sie standardmäßig hervorgehobene Bilder nur entfernen, indem Sie jeden Beitrag bearbeiten und das hervorgehobene Bild entfernen. Wenn nun ein Benutzer Hunderte von Beiträgen mit vorgestellten Bildern hat, kann es sehr zeitaufwändig sein, diese einzeln zu entfernen. Stattdessen werden wir einen anderen Ansatz versuchen. Wir werden eine Datenbankabfrage durchführen und die hervorgehobenen Bilder in allen Beiträgen entfernen.

Bevor Sie fortfahren, beachten Sie bitte, dass der unten stehende Code durch einfaches Einfügen die Featured Images aus allen Beiträgen auf Ihrer WordPress-Seite entfernt. Beachten Sie auch, dass dieser Code keine Ihrer hochgeladenen Bilder löscht. Sie sind weiterhin in der Mediathek verfügbar und können jederzeit wieder verwendet werden.

Alles, was Sie tun müssen, ist diesen Code zu kopieren und in die functions.php-Datei Ihres Themes einzufügen.


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

Das war’s schon. Sobald Sie Ihre functions.php-Datei speichern, führt dieses Skript eine Datenbankabfrage durch und entfernt die Featured Images aus allen Beiträgen.

Wichtig: Bitte entfernen Sie diesen Code sofort nach dem Speichern Ihrer functions.php-Datei. Sie können in WordPress keine Featured Images einstellen, da dieser Code weiterhin Featured Images aus Beiträgen entfernt.

Wir hoffen, dass dieser Artikel Ihnen geholfen hat, etwas Zeit zu sparen und es Ihnen ermöglicht hat, Featured Images aus WordPress-Beiträgen zu entfernen. Für Fragen und Feedback hinterlassen Sie bitte einen Kommentar unten.

Quelle: Kaiser

Offenlegung: Unsere Inhalte werden von unseren Lesern unterstützt. Das bedeutet, dass wir möglicherweise eine Provision verdienen, wenn Sie auf einige unserer Links klicken. Mehr dazu erfahren Sie unter Wie WPBeginner finanziert wird , warum das wichtig ist und wie Sie uns unterstützen können. Hier finden Sie unseren redaktionellen Prozess .

Das ultimative WordPress Toolkit

Erhalte KOSTENLOSEN Zugang zu unserem Toolkit - eine Sammlung von WordPress-bezogenen Produkten und Ressourcen, die jeder Profi haben sollte!

Reader Interactions

42 KommentareEine Antwort hinterlassen

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

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

  3. hercules says

    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.

  4. Em says

    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.

  5. Jax says

    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

  6. Mike says

    #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

  7. Raakib Hasan says

    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?

  8. Zaid Sparrow says

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

  9. Abdul says

    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

  10. w0ngsimp4ng says

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

  11. Marcelo says

    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?

  12. Rahul says

    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.

  13. Justin Edwards says

    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.

  14. UaMV says

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

Eine Antwort hinterlassen

Danke, dass du einen Kommentar hinterlassen möchtest. Bitte beachte, dass alle Kommentare nach unseren kommentarpolitik moderiert werden und deine E-Mail-Adresse NICHT veröffentlicht wird. Bitte verwende KEINE Schlüsselwörter im Namensfeld. Lass uns ein persönliches und sinnvolles Gespräch führen.