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

Como remover em massa as imagens em destaque das postagens no WordPress

Recentemente, um de nossos leitores nos perguntou como eles podem remover em massa as imagens em destaque das postagens no WordPress. No WPBeginner, discutimos as imagens em destaque (miniaturas de posts) muitas vezes. Mostramos a você como adicionar imagens em destaque no WordPress, como adicionar novos tamanhos de imagem no WordPress, como regenerar miniaturas e até mesmo como adicionar várias imagens em destaque a uma publicação no WordPress. Neste artigo, mostraremos como remover em massa as imagens em destaque das postagens no WordPress.

O problema com a remoção em massa de miniaturas de posts ou imagens em destaque

Infelizmente, por padrão, você só pode remover imagens em destaque editando cada postagem e removendo a imagem em destaque. Agora, se um usuário tiver centenas de publicações com imagens em destaque, removê-las uma a uma pode ser uma tarefa muito demorada. Em vez disso, tentaremos uma abordagem diferente. Executaremos uma consulta ao banco de dados e desmarcaremos as imagens em destaque em todas as postagens.

Antes de prosseguir, observe que o código abaixo removerá as imagens em destaque de todas as publicações em seu site do WordPress simplesmente colando-o. Observe também que esse código não excluirá nenhuma das imagens carregadas, elas ainda estarão disponíveis na Biblioteca de mídia e você poderá reutilizá-las a qualquer momento.

Tudo o que você precisa fazer é copiar e colar esse código no arquivo functions.php do seu tema.


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

Isso é tudo. Assim que você salvar o arquivo functions.php, esse script executará uma consulta ao banco de dados e removerá as imagens em destaque de todas as postagens.

Importante: remova esse código imediatamente após salvar o arquivo functions.php. Você não conseguirá definir as imagens em destaque no WordPress, pois esse código continuará removendo as imagens em destaque das postagens.

Esperamos que este artigo tenha ajudado você a economizar tempo e a remover em massa as imagens em destaque dos posts do WordPress. Em caso de dúvidas e feedback, deixe um comentário abaixo.

Fonte: Kaiser

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

41 ComentáriosLeave a Reply

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

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

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

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

  5. #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

  6. 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?

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

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

  9. 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?

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

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

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

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.