Last active
March 3, 2017 13:49
-
-
Save ilicfilip/a4567e634a49cc11fa36829c72d88fe6 to your computer and use it in GitHub Desktop.
Portfolio thumbnail column
This file contains 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
/* BEGIN: Add custom columns to admin screen */ | |
add_filter('manage_avada_portfolio_posts_columns', 'avada_portfolio_columns_head', 10); | |
function avada_portfolio_columns_head($existing_columns) { | |
$columns = array( | |
'cb' => $existing_columns['cb'], | |
'thumbnail' => '<span class="dashicons dashicons-format-image"></span>' | |
); | |
return array_merge( $columns, $existing_columns ); | |
} | |
add_action( 'manage_avada_portfolio_posts_custom_column' , 'avada_portfolio_custom_columns', 10, 2 ); | |
function avada_portfolio_custom_columns( $column, $post_id ) { | |
switch ( $column ) { | |
case 'thumbnail': | |
if( has_post_thumbnail($post_id) ) { | |
echo '<a href="' . get_edit_post_link( $post_id ) . '">'; | |
echo get_the_post_thumbnail( $post_id, 'thumbnail', array('style' => 'max-width:100%;height:auto;')); | |
echo '</a>'; | |
} | |
break; | |
} | |
} | |
/** | |
* Should actually be put into admin CSS file | |
*/ | |
add_action( 'admin_head', 'avada_portfolio_columns_css' ); | |
function avada_portfolio_columns_css() { | |
echo '<style>.manage-column.column-thumbnail{ width: 40px; text-align: center; }</style>'; | |
} | |
/* END: Add custom columns to admin screen */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment