X

Como adicionar a coluna de dimensões à biblioteca de mídia do WordPress

Snippets by IsItWP

Deseja adicionar uma coluna Dimensions à biblioteca de mídia do WordPress? A coluna Dimensions pode ajudar os usuários a entender a largura e a altura de suas imagens.

add media library column with images width and height wp_get_attachment_metadata

Instruções:

Tudo o que você precisa fazer é adicionar esse código ao arquivo functions.php do seu tema ou em um plug-in específico do site:

function wh_column( $cols ) {
	$cols["dimensions"] = "Dimensions (w, h)";
	return $cols;
}
function wh_value( $column_name, $id ) {
    $meta = wp_get_attachment_metadata($id);
           if(isset($meta['width']))
           echo $meta['width'].' x '.$meta['height'];
}
add_filter( 'manage_media_columns', 'wh_column' );
add_action( 'manage_media_custom_column', 'wh_value', 10, 2 );

Observação: Se esta é a primeira vez que você adiciona trechos de código no WordPress, consulte nosso guia sobre como copiar/colar corretamente trechos de código no WordPress para não danificar seu site acidentalmente.

Se você gostou desse snippet de código, considere dar uma olhada em nossos outros artigos no site, como: 62 melhores temas de blog gratuitos do WordPress ou 7 melhores plugins de formulário de contato do WordPress.

Comentários   Deixe uma resposta

  1. Hello,
    Thank you for this snippet. Any chance of making the Dimensions column sortable?
    Thanks again.

  2. This is great, thanks!

  3. Practical post ! I am thankful for the info ! Does anyone know where I could possibly obtain a blank OR Form 8.010.5 document to work with ?

  4. How can I go about adding dimensions to the “Media Library” tab in the Media Uploader?

  5. I suggest this code
    function wh_value( $column_name, $id ) {
        if ( $column_name == “dimensions” ):
        $meta = wp_get_attachment_metadata($id);
               if(isset($meta[‘width’]))
               echo $meta[‘width’].’ x ‘.$meta[‘height’];
        endif;
    }

    because if you have anothre column this code non rewrire the dimensions

    1. Brilliant, now I can combine it with the show ID snippet! Thank youu Andrea!

  6. Hi! Again, great snippet. Your website is a gold mine for a humble blogger like me 🙂
     
    I just added this code to my functions.php, the Dimensions (w, h) column appears, it works great. But if I look at the column next to it: ‘ID’ now I get the dimensions + ID number.

    Example:

    Dimensions (w, h) shows 400 x 300
    ID column shows 400 x 300 (nospace) 235 (which is the ID number) + one mysterious number between 1 and 5.

    Is it normal or is it just me? 🙂

    Thanks a lot!

    1. should not display that, what version of wordpress are you running?

      1. Hi Kevin, I’m using WP 3.0.4 and I have yet to upgrade, I know, I’m late 🙂

        1. Ill test things out in that version make sure it has no issues.

Adicionar um comentário

Ficamos felizes por você ter optado por deixar um comentário. Lembre-se de que todos os comentários são moderados de acordo com nossa política de privacidade, e todos os links são nofollow. NÃO use palavras-chave no campo do nome. Vamos ter uma conversa pessoal e significativa.

WordPress Launch Checklist

A lista de verificação definitiva para o lançamento do WordPress

Compilamos todos os itens essenciais da lista de verificação para o lançamento de seu próximo site WordPress em um ebook prático.
Sim, envie-me o livro eletrônico gratuito grátis!