X

Cómo añadir una miniatura destacada a las columnas de la entrada de administración

Snippets by IsItWP

¿Buscas una forma de añadir la miniatura de la imagen destacada a la lista de entradas en la administración de WordPress? Si bien es probable que haya un plugin para esto, hemos creado un fragmento de código rápido que puede utilizar para agregar la miniatura de la imagen destacada a las columnas del post de administración.

Instrucciones:

Todo lo que tienes que hacer es añadir este código al archivo functions.php de tu tema o en un plugin específico del sitio:

add_filter('manage_posts_columns', 'posts_columns', 5);
add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2);

function posts_columns($defaults){
    $defaults['riv_post_thumbs'] = __('Thumbs');
    return $defaults;
}

function posts_custom_columns($column_name, $id){
	if($column_name === 'riv_post_thumbs'){
        echo the_post_thumbnail( 'featured-thumbnail' );
    }
}

Nota: Si es la primera vez que añades fragmentos de código en WordPress, consulta nuestra guía sobre cómo añadir correctamente fragmentos de código en WordPress, para no romper accidentalmente tu sitio.

Si te ha gustado este fragmento de código, por favor, considere revisar nuestros otros artículos en el sitio como: 27 mejores temas de WordPress para blogs de viajes y cómo utilizar Google Optimize en WordPress.

Comentarios   Deja una respuesta

  1. I want a 🔗 in the media library if I don’t have an image

  2. Is there an update on this post. I’ve added the code to my functions file where other custom functions are functioning fine and it doesn’t add anything for extra images within standard or any of the custom post types I’ve created. Any help greatly appreciated. I am running WordPress 5.2.1

  3. When I use this code it brings my products post from woocommerce to my custom post type list.

  4. do i add it to my wp-include/functions.php ? i am using wp4

    1. thanks got it ! love ya !

      1. Cool glad you got it working.

  5. Just what i needed, thanks a lot for great snippet, and the update on how to set thumbnails size just nailed it 🙂

  6. thank you for the snippet. its very helpful as i start to add featured images in all my post. If i like to make this custom column “sortable”, how do i go that? i know its strange to sort image, i just want to see which post do not have image.

  7. Thanks.
    Helped me a lot

  8. Sergey Trushin mayo 7, 2013 en 9:59 pm

    Perfect code, thanks!

  9. hi kevin

    could you tell us how to reorder the e.g. 6 columns ???

    thumb – titel – date – user – cont – id
    to:
    id- titel – user – thumb – cont – date

    thanks you

  10. This is working just fine, however the new column is appearing on all custom post type edit screens as well. How would I go about just gettting this to appear on the edit post screens and not the edit CPT screens?

    1. Hi @5f9a29a8407e88a611b5bd004408018e:disqus I know I’m late but hoping this help other with same issue.

      Try this solution
      add_filter( ‘manage_edit-slider_columns’, ‘posts_columns’ ); // slider is the custom post-type you’ve created, feel free to update the post-type to which post-type you only want the custom column to display.

      Hope that helps

  11. Hi,

    I’d like to do that with a custom field value (‘facebook’) would that also be possible?

    Many thanks in advance!

    Cheers,
    Thomas.

    1. you could just get the custom field in the normal way eg:
      $custom_field = get_post_meta($post->ID, ‘facebook’, true);

      then echo the result to the page eg: echo $custom_field;

    2. @wpsnipp:disqus is right but before you can implement or call get_post_meta() function you need to add post_meta first 😉

  12. If post-thumbnails isn’t activated for the theme, only the 1st page/post is listed, with an error in the column.
    To add theme support (functions.php), this is added:
    if ( function_exists( ‘add_theme_support’ ) )add_theme_support( ‘post-thumbnails’ );

    What “IF” checks to see if the theme first supports post-thumbnails?

    1. I agree ill post an updated version of this snippet.

  13. hi, this might seem like a simple question, but where exactly do I place these snippets? functions.php?

    1. Hi onedeep99, yes you should add this snippet to the functions.php of your wordpress theme. I just updated the post to include that little detail as I forgot to mention it.

  14. Thank you for this great snippet. It is very useful to see if there is any thumbs in posts without opening them. Have just a few questions:

    1. Is it possible to get the same feature for the pages too?
    2. Is it possible to display all attached images in a post/page as thumbs instead of just one?
    3. Is it possible to define in which column the they appear in. I get them in the last column in the right of the screen but the default media library displays them in the first column at the left.

    Apreciate your concern 🙂

    1. Hi Zeb,
      1. yes you can ad this to pages as well just add these hooks. above the other hooks.

      add_filter(‘manage_pages_columns’, ‘posts_columns’, 5);
      add_action(‘manage_pages_custom_column’, ‘posts_custom_columns’, 5, 2);

      2. Yes you can reorder the columns Ill post some code asap.
      3. The problem with all attachments is that it may not have enough room for all attachments, Ill see if I can think of another way to display them. 

      1. Thanks alot kevin, 🙂
        If there is any way to specify a number in the snippet for the thumbs to be displayed so that,if needed, a user can change the number OR any other way you might think of would also be great.
        Thanks

        1. I’m not sure I understand can you elaborate a little?

        2. Sorry about not being clear.
          However, I was thinking about a maximum number of how many thumbs to be displayed. For instance, if there is space in the admin, a user can specify max 3 or 4 images to be displayed. Otherwise, “1” could mean only the first or the featured image, even if there is several attachments.
          Another way might be a kind of image rotator using any script.
          I hope I have been helpful 🙂

        3. Ahh ok I see what you mean, Ill look into this a little more could release this as a new snippet.

        4. Great Kevin, thanks 🙂

      2. Is there a way to do it for products?

  15. Thanks a lot for this snippet. Very useful!

    1. Cool glad you like the snippet, don’t forget to follow us on facebook or twitter we post new snippets daily.

  16. hi, I’ve added those snippet but there’s a little problem though. my featured thumbnail appeared in large size (original sizes I think). could you please show me how to resize thumbnail images in admin post columns if possible. thanks.

    1. Hi zarylnaxrie
      ‘featured-thumbnail’ would be a thumbnail size you created however if you replace the code on line nine above with the following.

      echo the_post_thumbnail( array(100,100) );

      Just change the size within the array, the follow page has more details on how post thumbnails function.

      http://codex.wordpress.org/Function_Reference/the_post_thumbnail

      1. Thank you soooooo much!!

  17. Tweets that mention Wordpress Add featured thumbnail to admin post columns – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com febrero 25, 2011 en 9:36 am

    […] This post was mentioned on Twitter by Y Combinator Newest!, newsery5 and wp_freak, WPSNIPP. WPSNIPP said: #wordpress Add featured thumbnail to admin post columns http://bit.ly/dHuROT #blog please RT 🙂 […]

Añadir un comentario

Nos alegra que haya decidido dejar un comentario. Tenga en cuenta que todos los comentarios se moderan de acuerdo con nuestra política de privacidad , y que todos los enlaces son nofollow. NO utilice palabras clave en el campo del nombre. Tengamos una conversación personal y significativa.

WordPress Launch Checklist

La lista definitiva para lanzar WordPress

Hemos recopilado todos los elementos esenciales de la lista de comprobación para el lanzamiento de su próximo sitio web de WordPress en un práctico ebook.
Sí, envíeme el ¡gratuito!