Skip to content

Instantly share code, notes, and snippets.

@jim912
Last active December 21, 2015 14:48
Show Gist options
  • Save jim912/6321922 to your computer and use it in GitHub Desktop.
Save jim912/6321922 to your computer and use it in GitHub Desktop.
add thumb column for post list
function add_thumbnail_column( $columns ) {
$columns['thumbnail'] = __( 'Featured Images' );
return $columns;
}
function display_thumbnail_column( $column_name, $post_id ) {
if ( $column_name == 'thumbnail' ) {
if ( has_post_thumbnail( $post_id ) ) {
echo get_the_post_thumbnail( $post_id, array( 50, 50 ) );
} else {
_e( 'none' );
}
}
}
function register_thumbnail_column_hooks() {
$post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : 'post';
if ( post_type_supports( $post_type, 'thumbnail' ) ) {
add_filter( 'manage_' . $post_type . '_posts_columns', 'add_thumbnail_column' );
add_action( 'manage_' . $post_type . '_posts_custom_column', 'display_thumbnail_column', 10, 2 );
}
}
add_action( 'load-edit.php', 'register_thumbnail_column_hooks' );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
add_action( 'admin_init', 'register_thumbnail_column_hooks' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment