• I’ve added 2 custom columns to the categories listings displayed in the admin area via wp-admin/edit-tags.php?taxonomy=category#

    To do so I used the following technique in my functions.php file so I don’t have to change wordpress core files:

    function manage_my_category_columns($columns)
    {
     if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'category' )
     return $columns;
    
     // add custom columns
     $columns['blurb'] = 'Blurb';
     $columns['image'] = 'Image';
    
     return $columns;
    }
    add_filter('manage_edit-category_columns','manage_my_category_columns');

    Because the addition of these 2 columns takes up more screen real estate, but the Add New Category column to the left of the categories listing box remains the stock size, there was overflow in some of my new columns that gets hidden.

    I wanted to reduce the size of the Add New Category column (where the user fills in a new category name, slug, and description and sets parent, if any) which is wider than required, and expand the width of the categories listing box to reduce or eliminate this overflow.

    I found A.J. Clark’s wonderful website wpexplorer.com and the ‘snippets’ section provided the clue.

    I used Firefox Web Developer extension to discover the css IDs of the left column and the category listing box column (along with those for the slug and post columns within the category listing box). Then it was a simple matter of adding this code:

    function custom_admin_css() {
    	echo '<style>
       	#col-left {
       		width: 25%;
    	}
    	#col-right {
      		width: 75%;
    	}
    	.fixed .column-slug {
      		width: 15%;
    	}
    	.fixed .column-posts {
      		width: 5%;
    	}
       	</style>';
     }
    add_action('admin_head', 'custom_admin_css');

    #col-left width was 35%, now reduced to 25%

    #col-right width was 65%, now expanded to 75%

    The slug and post columns were reduced to make room within the box for my custom columns.

    I had originally posted this as a question but found the solution right after I did so (isn’t that the way it often goes?) so thought I’d change it from question to solution in case anyone else is looking to do something similar.

  • The topic ‘change admin column width for Add New Category’ is closed to new replies.