Below are the simple steps to add feature Image column in WP Admin for custom post/post/page
1. Add the posts and pages columns filter. They can both use the same function.
1 2 3 | add_filter( 'manage_posts_columns' , 'tcb_add_post_thumbnail_column' , 5); add_filter( 'manage_pages_columns' , 'tcb_add_post_thumbnail_column' , 5); add_filter( 'manage_custom_post_columns' , 'tcb_add_post_thumbnail_column' , 5); |
2. Add the column
1 2 3 4 | function tcb_add_post_thumbnail_column( $cols ){ $cols [ 'tcb_post_thumb' ] = __( 'Featured Image' ); return $cols ; } |
3. Hook into the posts an pages column managing. Sharing function callback again.
1 2 3 | add_action( 'manage_posts_custom_column' , 'tcb_display_post_thumbnail_column' , 5, 2); add_action( 'manage_pages_custom_column' , 'tcb_display_post_thumbnail_column' , 5, 2); add_action( 'manage_custom_post_column' , 'tcb_display_post_thumbnail_column' , 5, 2); |
4.bGrab featured-thumbnail size post thumbnail and display it.
1 2 3 4 5 6 7 8 9 10 11 | function tcb_display_post_thumbnail_column( $col , $id ){ switch ( $col ){ case 'tcb_post_thumb' : if ( function_exists( 'the_post_thumbnail' ) ) echo the_post_thumbnail( 'featured-thumbnail' ); else echo 'Not supported in theme' ; break ; } } |
No comments:
Post a Comment