Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add Featured Image column before Title in the Posts list
- add_filter(
- 'manage_edit-post_columns',
- function ( $columns ) {
- $new = array();
- foreach ( $columns as $key => $label ) {
- if ( 'title' === $key ) {
- $new['featured_image'] = __( 'Featured Image', 'jnews' );
- }
- $new[ $key ] = $label;
- }
- return $new;
- },
- 20
- );
- // Output Featured Image in the column
- add_action(
- 'manage_post_posts_custom_column',
- function ( $column, $post_id ) {
- if ( 'featured_image' === $column ) {
- $thumb = get_the_post_thumbnail(
- $post_id,
- array( 60, 60 ),
- array(
- 'style' => 'display:block;width:60px;height:60px;object-fit:cover;border-radius:6px;',
- 'alt' => get_the_title( $post_id ),
- )
- );
- echo $thumb ?: '<span style="opacity:.6;">—</span>';
- }
- },
- 10,
- 2
- );
- // Adjust column width and alignment
- add_action(
- 'admin_head-edit.php',
- function () {
- echo '<style>.column-featured_image{width:72px;text-align:center}</style>';
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment