Wordpress - Style custom columns in admin panels (especially to adjust column cell widths)
I found a solution that works for me!
I dropped this code in functions.php :
add_action('admin_head', 'my_column_width');
function my_column_width() {
echo '<style type="text/css">';
echo '.column-mycolumn { text-align: center; width:60px !important; overflow:hidden }';
echo '</style>';
}
Thanks Nicusor: Works great. I was able to change the width of selected columns on the Posts panel (e.g Title, Author, Categories) with your solution as follows:
add_action('admin_head', 'my_admin_column_width');
function my_admin_column_width() {
echo '<style type="text/css">
.column-title { text-align: left; width:200px !important; overflow:hidden }
.column-author { text-align: left; width:100px !important; overflow:hidden }
.column-categories { text-align: left; width:100px !important; overflow:hidden }
</style>';
}
You should be able to set the column width using CSS quite easily. You can use the .column-{name}
class to apply styles to the column cells (both th
and td
). For example:
.column-mycolumn { width:20%; }
Make sure you don't have other styles overruling your column width because of CSS specificity rules. Also, long words without spaces or large images could force the column to be wider than specified in some browsers.