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

Cómo eliminar por lotes / en lotes las imágenes destacadas de las entradas en WordPress

Nota editorial: Ganamos una comisión de los enlaces de socios en WPBeginner. Las comisiones no afectan a las opiniones o evaluaciones de nuestros editores. Más información sobre Proceso editorial.

Recientemente uno de nuestros lectores nos preguntó cómo se pueden eliminar por lotes / en lotes las imágenes destacadas de las entradas en WordPress. En WPBeginner, hemos hablado de las imágenes destacadas (miniaturas de entradas) muchas veces. Le mostramos cómo añadir imágenes destacadas en WordPress, cómo añadir nuevos tamaños de imagen en WordPress, cómo regenerar miniaturas, incluso le mostramos cómo añadir múltiples imágenes destacadas a una entrada en WordPress. En este artículo le mostraremos cómo eliminar por lotes / en lotes las imágenes destacadas de las entradas en WordPress.

El problema con la eliminación masiva de miniaturas de entradas o imágenes destacadas

Desafortunadamente, por defecto solo se pueden eliminar imágenes destacadas editando cada entrada y quitando la imagen destacada. Ahora bien, si un usuario tiene cientos de entradas con imágenes destacadas, entonces quitarlas una por una puede ser una tarea que consuma mucho tiempo. En su lugar, vamos a intentar un enfoque diferente. Ejecutaremos una consulta a la base de datos y eliminaremos las imágenes destacadas de todas las entradas.

Antes de continuar, por favor tenga en cuenta que el código de abajo quitará las imágenes características de todas las entradas de su sitio WordPress simplemente pegándolo. Ten en cuenta también que este código no borrará ninguna de las imágenes subidas, seguirán estando disponibles en la biblioteca de medios y podrás reutilizarlas en cualquier momento.

Todo lo que necesitas hacer es copiar y pegar este código en el archivo functions. php de tu tema.


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

Eso es todo. Tan pronto como guardes tu archivo functions.php este script ejecutará una consulta a la base de datos y eliminará las imágenes destacadas de todas las entradas.

Importante: Por favor, quita este código inmediatamente después de guardar tu archivo functions.php. No podrás establecer las imágenes destacadas en WordPress ya que este código seguirá quitando las imágenes destacadas de las entradas.

Esperamos que este artículo te haya ayudado a ahorrar algo de tiempo y te haya permitido eliminar por lotes / en lotes las imágenes destacadas de las entradas de WordPress. Para preguntas y opiniones por favor deja un comentario abajo.

Fuente: Kaiser

Descargo: Nuestro contenido está apoyado por los lectores. Esto significa que si hace clic en algunos de nuestros enlaces, podemos ganar una comisión. Vea cómo se financia WPBeginner , por qué es importante, y cómo puede apoyarnos. Aquí está nuestro proceso editorial .

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.

El último kit de herramientas de WordPress

Obtenga acceso GRATUITO a nuestro kit de herramientas - una colección de productos y recursos relacionados con WordPress que todo profesional debería tener!

Reader Interactions

42 comentariosDeja una respuesta

  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?

Deja tu comentario

Gracias por elegir dejar un comentario. Tenga en cuenta que todos los comentarios son moderados de acuerdo con nuestros política de comentarios, y su dirección de correo electrónico NO será publicada. Por favor, NO utilice palabras clave en el campo de nombre. Tengamos una conversación personal y significativa.