Skip to content

Instantly share code, notes, and snippets.

@ewistrand
Last active November 19, 2015 13:31
Show Gist options
  • Save ewistrand/7bcd296ad5ee2eeaa092 to your computer and use it in GitHub Desktop.
Save ewistrand/7bcd296ad5ee2eeaa092 to your computer and use it in GitHub Desktop.
Wordpress Admin Thumbnails
<?php
/**
* Add Thumbnails To Admin & size them to max at 200px
*/
add_filter('manage_posts_columns', 'posts_columns', 5);
add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2);
/**
* Add CPT Thumbs replace post-type with CPT, not neccesary if post thumbnails are supported for all types
*/
add_filter('manage_post-type_posts_columns', 'posts_columns', 5);
add_action('manage_post-type_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'){
if( has_post_thumbnail() ) {
echo the_post_thumbnail('medium');
} else {
_e('No Thumbnail For Post');
}
echo "
<style>
.column-riv_post_thumbs img{
max-height: 300px;
max-width: 250px;
}
</style>
";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment