Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Forked from chrisrouse/Show Feature Image on Post Admin
Last active December 9, 2023 16:31
Show Gist options
  • Save Asikur22/6112a79ea9f078273c148d5aa622ac69 to your computer and use it in GitHub Desktop.
Save Asikur22/6112a79ea9f078273c148d5aa622ac69 to your computer and use it in GitHub Desktop.
Add column to Admin Table show the feature image of a post.
<?php
/*
* Adds the new column to the Admin Post View as the first column.
*/
function my_columns_filter( $columns ) {
$column_thumbnail = array( 'thumbnail' => 'Thumbnail' );
$columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, 1, null, true );
return $columns;
}
add_filter( 'manage_edit-post_columns', 'my_columns_filter' );
function my_column_action( $column ) {
if ( $column === 'thumbnail' && has_post_thumbnail() ) {
the_post_thumbnail( array( 80, 80 ) );
}
}
add_action( 'manage_posts_custom_column', 'my_column_action' );
/*
* Sets the width of the Thumbnail column.
*/
function wp98_column_width() {
$screen = get_current_screen();
if ( isset( $screen ) && $screen->id == 'edit-post' ) {
echo '<style type="text/css">';
echo '.column-thumbnail { width:80px !important; overflow:hidden }';
echo '.column-thumbnail img { width:80px !important; }';
echo '</style>';
}
}
add_action( 'admin_head', 'wp98_column_width' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment