Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mzdebo/cdbc1f2856784689434b0f2e646ac872 to your computer and use it in GitHub Desktop.
Save mzdebo/cdbc1f2856784689434b0f2e646ac872 to your computer and use it in GitHub Desktop.
Add a custom column with post thumbnail to the post overview
/* Add the post thumbnail to admin panel - marcokuemmel.de*/
function my_custom_column_content($column)
{
if ($column == 'featuredimage')
{
global $post;
echo (has_post_thumbnail($post->ID)) ? the_post_thumbnail(array(80,80)) : '<p>kein Bild festgelegt</p>' ;
}
}
// for cpt use manage_{$post_type}_posts_custom_column
add_action('manage_posts_custom_column', 'my_custom_column_content');
function my_custom_column_setup($columns)
{
return array_merge($columns, array('featuredimage'=>'Artikelbild'));
}
// replace posts with name of the post type to add the column on other post types
add_filter('manage_edit-posts_columns', 'my_custom_column_setup');
function my_admin_head()
{
echo '<style type="text/css"> body.wp-admin table.wp-list-table .column-featuredimage { width:10%; } </style>';
}
add_action('admin_head', 'my_admin_head');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment