Style custom columns in admin panels (especially to adjust column cell widths)

I am using WordPress as a CMS for a project which makes extensive use of custom post types. I need to display columns in admin panels for each custom post type in a different way.

I’ve already created the necessary columns and populated them. What I need to do is to adjust the CSS a bit. Most importantly I’m trying to tweak the width of certain columns. For example I don’t need a column listing the post ID to be as wide as the post name.

I enqueued a stylesheet in the admin panels for my custom post types but I can’t get it right to style the column widths.

I tried to adjust the max-width of th or td elements, but it’s ineffective. From firebug I can see the css style is there, but it’s doing nothing.

While I could find a lot of tutorials to add/edit custom columns, I didn’t really gather much information about how to style such columns. Any hint?

Thank you!

5

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>';
}

Leave a Comment