Forked from taricco/Show Featured Images in Admin Columns.php
Created
April 22, 2025 07:53
-
-
Save infocities/617b4c81d194aa0c2812fab5b846700a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Show Featured Images in admin columns | |
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/ | |
// Add filters for 'post' post type. | |
add_filter('manage_posts_columns', 'wsv_add_thumbnail_column', 5); | |
add_action('manage_posts_custom_column', 'wsv_display_thumbnail_column', 5, 2); | |
// Add filters for 'page' post type. | |
add_filter('manage_pages_columns', 'wsv_add_thumbnail_column', 5); | |
add_action('manage_pages_custom_column', 'wsv_display_thumbnail_column', 5, 2); | |
// Use the same function for adding thumbnail column for both posts and pages | |
function wsv_add_thumbnail_column($defaults) { | |
$defaults['wsv_post_thumbs'] = __('Featured Image'); | |
return $defaults; | |
} | |
// Use the same function for displaying thumbnail column for both posts and pages | |
function wsv_display_thumbnail_column($column_name, $id) { | |
if($column_name === 'wsv_post_thumbs'){ | |
echo the_post_thumbnail('thumbnail'); | |
} | |
} | |
// Function to add custom CSS for the thumbnail column | |
function wsv_custom_featuredimage_css() { | |
echo ' | |
<style type="text/css"> | |
.column-wsv_post_thumbs img { | |
width: 75px !important; | |
height: 75px !important; | |
overflow: hidden !important; | |
} | |
</style> | |
'; | |
} | |
// Hook the custom CSS function into the admin head | |
add_action('admin_head', 'wsv_custom_featuredimage_css'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment