Skip to content

Instantly share code, notes, and snippets.

@zakirsajib
Created February 5, 2020 06:19
Show Gist options
  • Save zakirsajib/a43ee125229703a508ea683f7dc2c2f7 to your computer and use it in GitHub Desktop.
Save zakirsajib/a43ee125229703a508ea683f7dc2c2f7 to your computer and use it in GitHub Desktop.
Add featured thumbnail to admin post columns
if ( function_exists( 'add_theme_support' ) ) {
add_filter( 'manage_posts_columns' , 'frontlash_add_custom_columns' );
add_action( 'manage_posts_custom_column' , 'frontlash_add_thumbnail_columns_data', 10, 2 );
add_action( 'manage_posts_custom_column' , 'frontlash_add_modified_author_columns_data', 10, 2 );
}
function frontlash_add_custom_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Title',
'featured_thumb' => 'Thumbnail',
'author' => 'Author',
'the_modified_author' => 'Last modified',
'categories' => 'Categories',
'tags' => 'Tags',
'comments' => '<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>',
'date' => 'Date'
);
return $columns;
}
function frontlash_add_thumbnail_columns_data( $column, $post_id ) {
switch ( $column ) {
case 'featured_thumb':
echo '<a href="' . get_edit_post_link() . '">';
echo the_post_thumbnail( 'admin-list-thumb' );
echo '</a>';
break;
}
}
add_image_size( 'admin-list-thumb', 80, 80, false );
function frontlash_add_modified_author_columns_data($column, $post_id){
switch ( $column ) {
case 'the_modified_author':
echo the_modified_author();
echo '<br>';
echo get_post_modified_time('F d, g:i a');
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment