Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've registered a new taxonomy for my custom post type, and now I'm trying to edit the taxonomy table.

I've successfully removed the description column but I can't figure it out how to edit column width for the column that shows the number of custom post types found in that particular taxonomy. The column's CSS class seems to be column-posts, and thus, its width is set to 10%.

Shouldn't the column's CSS class be column-{my-custom-post-type} and not the default?

Can I somehow force the column's width be set to auto or set its class to match my custom-post-type?

Here's what I've done so far:

Custom Post Type

function registerPersonnelPostType() {
    $labels = array(
        'name'                  => __( 'Personnel', 'xxx' ),
        'singular_name'         => __( 'Personnel', 'xxx' ),
        'add_new'               => __( 'Add New', 'xxx' ),
        'add_new_item'          => __( 'Add New Personnel Member', 'xxx' ),
        'edit_item'             => __( 'Edit Personnel Member', 'xxx' ),
        'new_item'              => __( 'New Personnel Member', 'xxx' ),
        'view_item'             => __( 'View Personnel Member', 'xxx' ),
        'search_items'          => __( 'Search Personnel', 'xxx' ),
        'not_found'             => __( 'No personnel found', 'xxx' ),
        'not_found_in_trash'    => __( 'No personnel found in Trash', 'xxx' ),
        'parent_item_colon'     => __( 'Parent Personnel:', 'xxx' ),
        'menu_name'             => __( 'Personnel', 'xxx' )
    );

    $args = array(
        'labels'                => $labels,
        'hierarchical'          => true,
        'description'           => 'Staff names and descriptions',
        'supports'              => array( 'title', 'editor', 'thumbnail' ),
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 20,
        'show_in_nav_menus'     => true,
        'publicly_queryable'    => true,
        'exclude_from_search'   => false,
        'has_archive'           => true,
        'query_var'             => true,
        'can_export'            => true,
        'rewrite'               => true,
        'capability_type'       => 'post'
    );

    register_post_type( 'personnel', $args );
}

Taxonomy

function departmentInit() {
    $labels = array(        
        'name'                  => __( 'Department', 'xxx' ),
        'singular_name'         => __( 'Department', 'xxx' ),
        'search_items'          => __( 'Search Departments', 'xxx' ),
        'all_items'             => __( 'All Departments', 'xxx' ),
        'parent_item'           => __( 'Parent Department', 'xxx' ),
        'parent_item_colon'     => __( 'Parent Department:', 'xxx' ),
        'edit_item'             => __( 'Edit Department', 'xxx' ),
        'update_item'           => __( 'Update Department', 'xxx' ),
        'add_new_item'          => __( 'Add New Department', 'xxx' ),
        'new_item_name'         => __( 'New Department Name', 'xxx' ),
        'menu_name'             => __( 'Department', 'xxx' )
    );

    $args = array(
        'labels'                => $labels,
        'hierarchical'          => true,
        'show_ui'               => true,
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'department' )
    );

    register_taxonomy( 'department' , array('personnel'), $args );
}

Hooks for editing columns

add_filter( 'manage_edit-department_columns', 'departmentColumns' );

function departmentColumns( $columns ) {    
    if ( isset( $columns[ 'description' ] ) ) {
        unset( $columns[ 'description' ] );
    }

    return $columns;        
}
share|improve this question

2 Answers 2

up vote 1 down vote accepted

This should do the trick:

add_action( 'admin_print_styles', 'cor_admin_print_styles', 200 );
function cor_admin_print_styles() {
    $screen = get_current_screen();
    if ( 'edit-tags' === $screen->base && 'department' === $screen->taxonomy ) {
        echo <<<EOF
<style>
    .fixed .column-posts {
        width: auto;
    }
    .widefat .num, .column-comments, .column-links, .column-posts {
        text-align: left;
    }
</style>
EOF;
    }
}
share|improve this answer
    
Magnificent! That really did the trick! Thank you! –  micadelli Feb 28 '13 at 13:02
    
Although I still don't get it why the column won't have a class name column-personnel –  micadelli Feb 28 '13 at 13:03
    
Thanks for the followup :) I know on different occasions a new <body> class will automatically be added. Also, if you really need to change a lot of CSS, you could always add one yourself. deluxeblogtips.com/2013/02/wordpress-admin-body-class.html –  Cor van Noorloos Feb 28 '13 at 13:13
    
As a side-note @kaiser (and stephenharris) recently made a great plugin which displays most info about the current admin screen globals, contextual hooks, etc. (terribly sorry about the double comment/links, but I do think all are quite relevant to the original question) –  Cor van Noorloos Feb 28 '13 at 13:29

Add following code in functions.php file to achieve this :

add_action('admin_head', 'my_custom_fonts');

function my_custom_fonts() {
  echo '<style>
   #posts.column-posts{width:auto;}
} 
</style>';
}
share|improve this answer
1  
Thanks for your input. However, this is partly the solution – that would also change all other tables, eg. categories which is I want to prevent. –  micadelli Feb 28 '13 at 10:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.